Skip to content

Commit 093720f

Browse files
chore: Add more UiAutomator2 options (#1545)
1 parent eafcd94 commit 093720f

25 files changed

+1347
-5
lines changed

src/main/java/io/appium/java_client/android/options/UiAutomator2Options.java

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616

1717
package io.appium.java_client.android.options;
1818

19+
import io.appium.java_client.android.options.adb.SupportsAdbExecTimeoutOption;
20+
import io.appium.java_client.android.options.adb.SupportsAdbPortOption;
21+
import io.appium.java_client.android.options.adb.SupportsAllowDelayAdbOption;
22+
import io.appium.java_client.android.options.adb.SupportsBuildToolsVersionOption;
23+
import io.appium.java_client.android.options.adb.SupportsClearDeviceLogsOnStartOption;
24+
import io.appium.java_client.android.options.adb.SupportsIgnoreHiddenApiPolicyErrorOption;
25+
import io.appium.java_client.android.options.adb.SupportsLogcatFilterSpecsOption;
26+
import io.appium.java_client.android.options.adb.SupportsLogcatFormatOption;
27+
import io.appium.java_client.android.options.adb.SupportsMockLocationAppOption;
28+
import io.appium.java_client.android.options.adb.SupportsRemoteAdbHostOption;
29+
import io.appium.java_client.android.options.adb.SupportsSkipLogcatCaptureOption;
30+
import io.appium.java_client.android.options.adb.SupportsSuppressKillServerOption;
1931
import io.appium.java_client.android.options.app.SupportsAllowTestPackagesOption;
2032
import io.appium.java_client.android.options.app.SupportsAndroidInstallTimeoutOption;
2133
import io.appium.java_client.android.options.app.SupportsAppActivityOption;
@@ -32,13 +44,24 @@
3244
import io.appium.java_client.android.options.app.SupportsOptionalIntentArgumentsOption;
3345
import io.appium.java_client.android.options.app.SupportsRemoteAppsCacheLimitOption;
3446
import io.appium.java_client.android.options.app.SupportsUninstallOtherPackagesOption;
47+
import io.appium.java_client.android.options.avd.SupportsAvdArgsOption;
48+
import io.appium.java_client.android.options.avd.SupportsAvdEnvOption;
49+
import io.appium.java_client.android.options.avd.SupportsAvdLaunchTimeoutOption;
50+
import io.appium.java_client.android.options.avd.SupportsAvdOption;
51+
import io.appium.java_client.android.options.avd.SupportsAvdReadyTimeoutOption;
52+
import io.appium.java_client.android.options.avd.SupportsGpsEnabledOption;
53+
import io.appium.java_client.android.options.avd.SupportsIsHeadlessOption;
54+
import io.appium.java_client.android.options.avd.SupportsNetworkSpeedOption;
55+
import io.appium.java_client.android.options.localization.SupportsLocaleScriptOption;
3556
import io.appium.java_client.android.options.server.SupportsDisableWindowAnimationOption;
3657
import io.appium.java_client.android.options.server.SupportsSkipDeviceInitializationOption;
3758
import io.appium.java_client.android.options.server.SupportsSkipServerInstallationOption;
3859
import io.appium.java_client.android.options.server.SupportsSystemPortOption;
3960
import io.appium.java_client.android.options.server.SupportsUiautomator2ServerInstallTimeoutOption;
4061
import io.appium.java_client.android.options.server.SupportsUiautomator2ServerLaunchTimeoutOption;
4162
import io.appium.java_client.android.options.server.SupportsUiautomator2ServerReadTimeoutOption;
63+
import io.appium.java_client.android.options.signing.SupportsKeystoreOptions;
64+
import io.appium.java_client.android.options.signing.SupportsNoSignOption;
4265
import io.appium.java_client.remote.AutomationName;
4366
import io.appium.java_client.remote.MobilePlatform;
4467
import io.appium.java_client.remote.options.BaseOptions;
@@ -58,9 +81,6 @@
5881
* https://github.com/appium/appium-uiautomator2-driver#capabilities
5982
*/
6083
public class UiAutomator2Options extends BaseOptions<UiAutomator2Options> implements
61-
// TODO: ADB options: https://github.com/appium/appium-uiautomator2-driver#adb
62-
// TODO: AVD options: https://github.com/appium/appium-uiautomator2-driver#emulator-android-virtual-device
63-
// TODO: App signing options: https://github.com/appium/appium-uiautomator2-driver#app-signing
6484
// TODO: Device locking options: https://github.com/appium/appium-uiautomator2-driver#device-locking
6585
// TODO: MJPEG options: https://github.com/appium/appium-uiautomator2-driver#mjpeg
6686
// TODO: Web Context options: https://github.com/appium/appium-uiautomator2-driver#web-context
@@ -100,9 +120,35 @@ public class UiAutomator2Options extends BaseOptions<UiAutomator2Options> implem
100120
SupportsAllowTestPackagesOption<UiAutomator2Options>,
101121
SupportsRemoteAppsCacheLimitOption<UiAutomator2Options>,
102122
SupportsEnforceAppInstallOption<UiAutomator2Options>,
103-
// TODO: App localization options: https://github.com/appium/appium-uiautomator2-driver#app-localization
123+
// App localization options: https://github.com/appium/appium-uiautomator2-driver#app-localization
124+
SupportsLocaleScriptOption<UiAutomator2Options>,
104125
SupportsLanguageOption<UiAutomator2Options>,
105-
SupportsLocaleOption<UiAutomator2Options> {
126+
SupportsLocaleOption<UiAutomator2Options>,
127+
// ADB options: https://github.com/appium/appium-uiautomator2-driver#adb
128+
SupportsAdbPortOption<UiAutomator2Options>,
129+
SupportsRemoteAdbHostOption<UiAutomator2Options>,
130+
SupportsAdbExecTimeoutOption<UiAutomator2Options>,
131+
SupportsClearDeviceLogsOnStartOption<UiAutomator2Options>,
132+
SupportsBuildToolsVersionOption<UiAutomator2Options>,
133+
SupportsSkipLogcatCaptureOption<UiAutomator2Options>,
134+
SupportsSuppressKillServerOption<UiAutomator2Options>,
135+
SupportsIgnoreHiddenApiPolicyErrorOption<UiAutomator2Options>,
136+
SupportsMockLocationAppOption<UiAutomator2Options>,
137+
SupportsLogcatFormatOption<UiAutomator2Options>,
138+
SupportsLogcatFilterSpecsOption<UiAutomator2Options>,
139+
SupportsAllowDelayAdbOption<UiAutomator2Options>,
140+
// AVD options: https://github.com/appium/appium-uiautomator2-driver#emulator-android-virtual-device
141+
SupportsAvdOption<UiAutomator2Options>,
142+
SupportsAvdLaunchTimeoutOption<UiAutomator2Options>,
143+
SupportsAvdReadyTimeoutOption<UiAutomator2Options>,
144+
SupportsAvdArgsOption<UiAutomator2Options>,
145+
SupportsAvdEnvOption<UiAutomator2Options>,
146+
SupportsNetworkSpeedOption<UiAutomator2Options>,
147+
SupportsGpsEnabledOption<UiAutomator2Options>,
148+
SupportsIsHeadlessOption<UiAutomator2Options>,
149+
// App signing options: https://github.com/appium/appium-uiautomator2-driver#app-signing
150+
SupportsKeystoreOptions<UiAutomator2Options>,
151+
SupportsNoSignOption<UiAutomator2Options> {
106152
public UiAutomator2Options() {
107153
setCommonOptions();
108154
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.android.options.adb;
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.time.Duration;
24+
import java.util.Optional;
25+
26+
import static io.appium.java_client.internal.CapabilityHelpers.toDuration;
27+
28+
public interface SupportsAdbExecTimeoutOption<T extends BaseOptions<T>> extends
29+
Capabilities, CanSetCapability<T> {
30+
String ADB_EXEC_TIMEOUT_OPTION = "adbExecTimeout";
31+
32+
/**
33+
* Maximum time to wait until single ADB command is executed.
34+
* 20000 ms by default.
35+
*
36+
* @param timeout ADB commands timeout.
37+
* @return self instance for chaining.
38+
*/
39+
default T setAdbExecTimeout(Duration timeout) {
40+
return amend(ADB_EXEC_TIMEOUT_OPTION, timeout.toMillis());
41+
}
42+
43+
/**
44+
* Get maximum time to wait until single ADB command is executed.
45+
*
46+
* @return Timeout value.
47+
*/
48+
default Optional<Duration> getAdbExecTimeout() {
49+
return Optional.ofNullable(toDuration(getCapability(ADB_EXEC_TIMEOUT_OPTION)));
50+
}
51+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.android.options.adb;
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+
import static io.appium.java_client.internal.CapabilityHelpers.toInteger;
26+
27+
public interface SupportsAdbPortOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String ADB_PORT_OPTION = "adbPort";
30+
31+
/**
32+
* Set number of the port where ADB is running. 5037 by default
33+
*
34+
* @param port port number in range 0..65535
35+
* @return self instance for chaining.
36+
*/
37+
default T setAdbPort(int port) {
38+
return amend(ADB_PORT_OPTION, port);
39+
}
40+
41+
/**
42+
* Get number of the port where ADB is running.
43+
*
44+
* @return Adb port value
45+
*/
46+
default Optional<Integer> getAdbPort() {
47+
return Optional.ofNullable(toInteger(getCapability(ADB_PORT_OPTION)));
48+
}
49+
}
Lines changed: 50 additions & 0 deletions
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.android.options.adb;
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+
import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean;
26+
27+
public interface SupportsAllowDelayAdbOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String ALLOW_DELAY_ADB_OPTION = "allowDelayAdb";
30+
31+
/**
32+
* Being set to false prevents emulator to use -delay-adb feature to detect its startup.
33+
* See https://github.com/appium/appium/issues/14773 for more details.
34+
*
35+
* @param value Set it to false in order to prevent the emulator to use -delay-adb feature.
36+
* @return self instance for chaining.
37+
*/
38+
default T setAllowDelayAdb(boolean value) {
39+
return amend(ALLOW_DELAY_ADB_OPTION, value);
40+
}
41+
42+
/**
43+
* Get whether to prevent the emulator to use -delay-adb feature.
44+
*
45+
* @return True or false.
46+
*/
47+
default Optional<Boolean> doesAllowDelayAdb() {
48+
return Optional.ofNullable(toSafeBoolean(getCapability(ALLOW_DELAY_ADB_OPTION)));
49+
}
50+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.android.options.adb;
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 SupportsBuildToolsVersionOption<T extends BaseOptions<T>> extends
26+
Capabilities, CanSetCapability<T> {
27+
String BUILD_TOOLS_VERSION_OPTION = "buildToolsVersion";
28+
29+
/**
30+
* The version of Android build tools to use. By default, UiAutomator2
31+
* driver uses the most recent version of build tools installed on
32+
* the machine, but sometimes it might be necessary to give it a hint
33+
* (let say if there is a known bug in the most recent tools version).
34+
* Example: 28.0.3
35+
*
36+
* @param version The build tools version to use.
37+
* @return self instance for chaining.
38+
*/
39+
default T setBuildToolsVersion(String version) {
40+
return amend(BUILD_TOOLS_VERSION_OPTION, version);
41+
}
42+
43+
/**
44+
* Get the version of Android build tools to use.
45+
*
46+
* @return Build tools version.
47+
*/
48+
default Optional<String> getBuildToolsVersion() {
49+
return Optional.ofNullable((String) getCapability(BUILD_TOOLS_VERSION_OPTION));
50+
}
51+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.android.options.adb;
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+
import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean;
26+
27+
public interface SupportsClearDeviceLogsOnStartOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String CLEAR_DEVICE_LOGS_ON_START_OPTION = "clearDeviceLogsOnStart";
30+
31+
/**
32+
* Makes UiAutomator2 to delete all the existing logs in the
33+
* device buffer before starting a new test.
34+
*
35+
* @return self instance for chaining.
36+
*/
37+
default T clearDeviceLogsOnStart() {
38+
return amend(CLEAR_DEVICE_LOGS_ON_START_OPTION, true);
39+
}
40+
41+
42+
/**
43+
* If set to true then UiAutomator2 deletes all the existing logs in the
44+
* device buffer before starting a new test.
45+
*
46+
* @param value Set to false if you don't want to wait for the app to finish its launch.
47+
* @return self instance for chaining.
48+
*/
49+
default T setClearDeviceLogsOnStart(boolean value) {
50+
return amend(CLEAR_DEVICE_LOGS_ON_START_OPTION, value);
51+
}
52+
53+
/**
54+
* Get whether to delete all the existing logs in the
55+
* device buffer before starting a new test.
56+
*
57+
* @return True or false.
58+
*/
59+
default Optional<Boolean> doesClearDeviceLogsOnStart() {
60+
return Optional.ofNullable(toSafeBoolean(getCapability(CLEAR_DEVICE_LOGS_ON_START_OPTION)));
61+
}
62+
}

0 commit comments

Comments
 (0)