Skip to content

Commit 7013e56

Browse files
feat: Add Mac2 driver options (#1565)
1 parent 73c44c6 commit 7013e56

14 files changed

+780
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.mac.options;
18+
19+
import io.appium.java_client.remote.AutomationName;
20+
import io.appium.java_client.remote.MobilePlatform;
21+
import io.appium.java_client.remote.options.BaseOptions;
22+
import org.openqa.selenium.Capabilities;
23+
24+
import java.util.Map;
25+
26+
/**
27+
* https://github.com/appium/appium-mac2-driver#capabilities
28+
*/
29+
public class Mac2Options extends BaseOptions<Mac2Options> implements
30+
SupportsSystemPortOption<Mac2Options>,
31+
SupportsSystemHostOption<Mac2Options>,
32+
SupportsWebDriverAgentMacUrlOption<Mac2Options>,
33+
SupportsBootstrapRootOption<Mac2Options>,
34+
SupportsBundleIdOption<Mac2Options>,
35+
SupportsArgumentsOption<Mac2Options>,
36+
SupportsEnvironmentOption<Mac2Options>,
37+
SupportsServerStartupTimeoutOption<Mac2Options>,
38+
SupportsSkipAppKillOption<Mac2Options>,
39+
SupportsShowServerLogsOption<Mac2Options>,
40+
SupportsPrerunOption<Mac2Options>,
41+
SupportsPostrunOption<Mac2Options> {
42+
public Mac2Options() {
43+
setCommonOptions();
44+
}
45+
46+
public Mac2Options(Capabilities source) {
47+
super(source);
48+
setCommonOptions();
49+
}
50+
51+
public Mac2Options(Map<String, ?> source) {
52+
super(source);
53+
setCommonOptions();
54+
}
55+
56+
private void setCommonOptions() {
57+
setPlatformName(MobilePlatform.MAC);
58+
setAutomationName(AutomationName.MAC2);
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.mac.options;
18+
19+
import io.appium.java_client.remote.options.BaseMapOptionData;
20+
21+
import java.util.Map;
22+
import java.util.Optional;
23+
24+
public class RunScript extends BaseMapOptionData<RunScript> {
25+
public RunScript() {
26+
}
27+
28+
public RunScript(Map<String, Object> options) {
29+
super(options);
30+
}
31+
32+
/**
33+
* Allows to provide a multiline AppleScript.
34+
*
35+
* @param script A valid AppleScript.
36+
* @return self instance for chaining.
37+
*/
38+
public RunScript withScript(String script) {
39+
return assignOptionValue("script", script);
40+
}
41+
42+
/**
43+
* Get a multiline AppleScript.
44+
*
45+
* @return AppleScript snippet.
46+
*/
47+
public Optional<String> getScript() {
48+
return getOptionValue("script");
49+
}
50+
51+
/**
52+
* Allows to provide a single-line AppleScript.
53+
*
54+
* @param command A valid AppleScript.
55+
* @return self instance for chaining.
56+
*/
57+
public RunScript withCommand(String command) {
58+
return assignOptionValue("command", command);
59+
}
60+
61+
/**
62+
* Get a single-line AppleScript.
63+
*
64+
* @return AppleScript snippet.
65+
*/
66+
public Optional<String> getCommand() {
67+
return getOptionValue("command");
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.mac.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.List;
24+
import java.util.Optional;
25+
26+
public interface SupportsArgumentsOption<T extends BaseOptions<T>> extends
27+
Capabilities, CanSetCapability<T> {
28+
String ARGUMENTS_OPTION = "arguments";
29+
30+
/**
31+
* Array of application command line arguments. This capability is
32+
* only going to be applied if the application is not running on session startup.
33+
*
34+
* @param arguments E.g. ["--help"].
35+
* @return self instance for chaining.
36+
*/
37+
default T setArguments(List<String> arguments) {
38+
return amend(ARGUMENTS_OPTION, arguments);
39+
}
40+
41+
/**
42+
* Get the array of application command line arguments.
43+
*
44+
* @return Application arguments.
45+
*/
46+
default Optional<List<String>> getArguments() {
47+
//noinspection unchecked
48+
return Optional.ofNullable((List<String>) getCapability(ARGUMENTS_OPTION));
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.mac.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
public interface SupportsBootstrapRootOption<T extends BaseOptions<T>> extends
26+
Capabilities, CanSetCapability<T> {
27+
String BOOTSTRAP_ROOT_OPTION = "bootstrapRoot";
28+
29+
/**
30+
* The full path to WebDriverAgentMac root folder where Xcode project
31+
* of the server sources lives. By default, this project is located in
32+
* the same folder where the corresponding driver Node.js module lives.
33+
*
34+
* @param path The full path to WebDriverAgentMac root folder.
35+
* @return self instance for chaining.
36+
*/
37+
default T setBootstrapRoot(String path) {
38+
return amend(BOOTSTRAP_ROOT_OPTION, path);
39+
}
40+
41+
/**
42+
* Get the full path to WebDriverAgentMac root folder where Xcode project
43+
* of the server sources lives.
44+
*
45+
* @return The full path to WebDriverAgentMac root folder.
46+
*/
47+
default Optional<String> getBootstrapRoot() {
48+
return Optional.ofNullable((String) getCapability(BOOTSTRAP_ROOT_OPTION));
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.mac.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
public interface SupportsBundleIdOption<T extends BaseOptions<T>> extends
26+
Capabilities, CanSetCapability<T> {
27+
String BUNDLE_ID_OPTION = "bundleId";
28+
29+
/**
30+
* The bundle identifier of the application to automate, for example
31+
* com.apple.TextEdit. This is an optional capability. If it is not provided
32+
* then the session will be started without an application under test
33+
* (actually, it will be Finder). If the application with the given
34+
* identifier is not installed then an error will be thrown on session
35+
* startup. If the application is already running then it will be moved to
36+
* the foreground.
37+
*
38+
* @param identifier A valid application bundle identifier.
39+
* @return self instance for chaining.
40+
*/
41+
default T setBundleId(String identifier) {
42+
return amend(BUNDLE_ID_OPTION, identifier);
43+
}
44+
45+
/**
46+
* Get the bundle identifier of the application to automate.
47+
*
48+
* @return Application bundle identifier.
49+
*/
50+
default Optional<String> getBundleId() {
51+
return Optional.ofNullable((String) getCapability(BUNDLE_ID_OPTION));
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.mac.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.List;
24+
import java.util.Optional;
25+
26+
public interface SupportsEnvironmentOption<T extends BaseOptions<T>> extends
27+
Capabilities, CanSetCapability<T> {
28+
String ENVIRONMENT_OPTION = "environment";
29+
30+
/**
31+
* A dictionary of environment variables (name-&gt;value) that are going to be passed
32+
* to the application under test on top of environment variables inherited from
33+
* the parent process. This capability is only going to be applied if the application
34+
* is not running on session startup.
35+
*
36+
* @param arguments E.g. ["--help"].
37+
* @return self instance for chaining.
38+
*/
39+
default T setEnvironment(List<String> arguments) {
40+
return amend(ENVIRONMENT_OPTION, arguments);
41+
}
42+
43+
/**
44+
* Get the application environment variables mapping.
45+
*
46+
* @return Application environment mapping.
47+
*/
48+
default Optional<List<String>> getEnvironment() {
49+
//noinspection unchecked
50+
return Optional.ofNullable((List<String>) getCapability(ENVIRONMENT_OPTION));
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.mac.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Map;
24+
import java.util.Optional;
25+
26+
public interface SupportsPostrunOption<T extends BaseOptions<T>> extends
27+
Capabilities, CanSetCapability<T> {
28+
String POSTRUN_OPTION = "postrun";
29+
30+
/**
31+
* An object containing either script or command key. The value of
32+
* each key must be a valid AppleScript script or command to be
33+
* executed after Mac2Driver session is stopped. See
34+
* https://github.com/appium/appium-mac2-driver#applescript-commands-execution
35+
* for more details.
36+
*
37+
* @param script A valid AppleScript snippet.
38+
* @return self instance for chaining.
39+
*/
40+
default T setPostrun(RunScript script) {
41+
return amend(POSTRUN_OPTION, script.toMap());
42+
}
43+
44+
/**
45+
* Get the postrun script.
46+
*
47+
* @return Postrun script.
48+
*/
49+
default Optional<RunScript> getPostrun() {
50+
//noinspection unchecked
51+
return Optional.ofNullable(getCapability(POSTRUN_OPTION))
52+
.map((v) -> new RunScript((Map<String, Object>) v));
53+
}
54+
}

0 commit comments

Comments
 (0)