Skip to content

Commit 9d33a4e

Browse files
mykola-mokhnachsaikrishna321
authored andcommitted
Add the missing Android and iOS settings (#1120)
* Add the missing Android and iOS settings * Tune docs * Fix docstrings
1 parent 392413f commit 9d33a4e

File tree

3 files changed

+158
-13
lines changed

3 files changed

+158
-13
lines changed

src/main/java/io/appium/java_client/Setting.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,37 @@
1818

1919
/**
2020
* Enums defining constants for Appium Settings which can be set and toggled during a test session.
21+
* http://appium.io/docs/en/advanced-concepts/settings/
2122
*/
2223
public enum Setting {
2324

25+
// Android
2426
IGNORE_UNIMPORTANT_VIEWS("ignoreUnimportantViews"),
2527
WAIT_FOR_IDLE_TIMEOUT("waitForIdleTimeout"),
2628
WAIT_FOR_SELECTOR_TIMEOUT("waitForSelectorTimeout"),
2729
WAIT_SCROLL_ACKNOWLEDGMENT_TIMEOUT("scrollAcknowledgmentTimeout"),
2830
WAIT_ACTION_ACKNOWLEDGMENT_TIMEOUT("actionAcknowledgmentTimeout"),
31+
ALLOW_INVISIBLE_ELEMENTS("allowInvisibleElements"),
32+
ENABLE_NOTIFICATION_LISTENER("enableNotificationListener"),
33+
NORMALIZE_TAG_NAMES("normalizeTagNames"),
2934
KEY_INJECTION_DELAY("keyInjectionDelay"),
35+
// iOS
36+
MJPEG_SERVER_SCREENSHOT_QUALITY("mjpegServerScreenshotQuality"),
37+
MJPEG_SERVER_FRAMERATE("mjpegServerFramerate"),
38+
SCREENSHOT_QUALITY("screenshotQuality"),
3039
NATIVE_WEB_TAP("nativeWebTap"),
40+
// Android and iOS
41+
SHOULD_USE_COMPACT_RESPONSES("shouldUseCompactResponses"),
42+
ELEMENT_RESPONSE_ATTRIBUTES("elementResponseAttributes"),
43+
// All platforms
44+
IMAGE_ELEMENT_TAP_STRATEGY("imageElementTapStrategy"),
3145
IMAGE_MATCH_THRESHOLD("imageMatchThreshold"),
3246
FIX_IMAGE_FIND_SCREENSHOT_DIMENSIONS("fixImageFindScreenshotDims"),
3347
FIX_IMAGE_TEMPLATE_SIZE("fixImageTemplateSize"),
3448
CHECK_IMAGE_ELEMENT_STALENESS("checkForImageElementStaleness"),
35-
UPDATE_IMAGE_ELEMENT_POSITION("autoUpdateImageElementPosition"),
36-
NORMALIZE_TAG_NAMES("normalizeTagNames"),
37-
IMAGE_ELEMENT_TAP_STRATEGY("imageElementTapStrategy");
49+
UPDATE_IMAGE_ELEMENT_POSITION("autoUpdateImageElementPosition");
3850

39-
private String name;
51+
private final String name;
4052

4153
Setting(String name) {
4254
this.name = name;

src/main/java/io/appium/java_client/android/HasAndroidSettings.java

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,59 +30,71 @@ interface HasAndroidSettings extends HasSettings {
3030
* by the system), in an attempt to make things less confusing or faster.
3131
*
3232
* @param compress ignores unimportant views if true, doesn't ignore otherwise.
33+
* @return self instance for chaining
3334
*/
34-
default void ignoreUnimportantViews(Boolean compress) {
35+
default HasAndroidSettings ignoreUnimportantViews(Boolean compress) {
3536
setSetting(Setting.IGNORE_UNIMPORTANT_VIEWS, compress);
37+
return this;
3638
}
3739

3840
/**
3941
* invoke {@code setWaitForIdleTimeout} in {@code com.android.uiautomator.core.Configurator}.
4042
*
4143
* @param timeout A negative value would reset to its default value. Minimum time unit
4244
* resolution is one millisecond
45+
* @return self instance for chaining
4346
*/
44-
default void configuratorSetWaitForIdleTimeout(Duration timeout) {
47+
default HasAndroidSettings configuratorSetWaitForIdleTimeout(Duration timeout) {
4548
setSetting(Setting.WAIT_FOR_IDLE_TIMEOUT, timeout.toMillis());
49+
return this;
4650
}
4751

4852
/**
4953
* invoke {@code setWaitForSelectorTimeout} in {@code com.android.uiautomator.core.Configurator}.
5054
*
5155
* @param timeout A negative value would reset to its default value. Minimum time unit
5256
* resolution is one millisecond
57+
* @return self instance for chaining
5358
*/
54-
default void configuratorSetWaitForSelectorTimeout(Duration timeout) {
59+
default HasAndroidSettings configuratorSetWaitForSelectorTimeout(Duration timeout) {
5560
setSetting(Setting.WAIT_FOR_SELECTOR_TIMEOUT, timeout.toMillis());
61+
return this;
5662
}
5763

5864
/**
5965
* invoke {@code setScrollAcknowledgmentTimeout} in {@code com.android.uiautomator.core.Configurator}.
6066
*
6167
* @param timeout A negative value would reset to its default value. Minimum time unit
6268
* resolution is one millisecond
69+
* @return self instance for chaining
6370
*/
64-
default void configuratorSetScrollAcknowledgmentTimeout(Duration timeout) {
71+
default HasAndroidSettings configuratorSetScrollAcknowledgmentTimeout(Duration timeout) {
6572
setSetting(Setting.WAIT_SCROLL_ACKNOWLEDGMENT_TIMEOUT, timeout.toMillis());
73+
return this;
6674
}
6775

6876
/**
6977
* invoke {@code configuratorSetKeyInjectionDelay} in {@code com.android.uiautomator.core.Configurator}.
7078
*
7179
* @param delay A negative value would reset to its default value. Minimum time unit
7280
* resolution is one millisecond
81+
* @return self instance for chaining
7382
*/
74-
default void configuratorSetKeyInjectionDelay(Duration delay) {
83+
default HasAndroidSettings configuratorSetKeyInjectionDelay(Duration delay) {
7584
setSetting(Setting.KEY_INJECTION_DELAY, delay.toMillis());
85+
return this;
7686
}
7787

7888
/**
7989
* invoke {@code setActionAcknowledgmentTimeout} in {@code com.android.uiautomator.core.Configurator}.
8090
*
8191
* @param timeout A negative value would reset to its default value. Minimum time unit
8292
* resolution is one millisecond
93+
* @return self instance for chaining
8394
*/
84-
default void configuratorSetActionAcknowledgmentTimeout(Duration timeout) {
95+
default HasAndroidSettings configuratorSetActionAcknowledgmentTimeout(Duration timeout) {
8596
setSetting(Setting.WAIT_ACTION_ACKNOWLEDGMENT_TIMEOUT, timeout.toMillis());
97+
return this;
8698
}
8799

88100
/**
@@ -93,10 +105,64 @@ default void configuratorSetActionAcknowledgmentTimeout(Duration timeout) {
93105
* XML parsing exceptions caused by XPath lookup.
94106
* The Unicode to ASCII transliteration is based on
95107
* JUnidecode library (https://github.com/gcardone/junidecode).
108+
* Works for UIAutomator2 only.
96109
*
97110
* @param enabled Either true or false. The default value if false.
111+
* @return self instance for chaining
98112
*/
99-
default void normalizeTagNames(boolean enabled) {
113+
default HasAndroidSettings normalizeTagNames(boolean enabled) {
100114
setSetting(Setting.NORMALIZE_TAG_NAMES, enabled);
115+
return this;
116+
}
117+
118+
/**
119+
* Whether to return compact (standards-compliant) and faster responses in find element/s
120+
* (the default setting). If set to false then the response may also contain other
121+
* available element attributes.
122+
*
123+
* @param enabled Either true or false. The default value if true.
124+
* @return self instance for chaining
125+
*/
126+
default HasAndroidSettings setShouldUseCompactResponses(boolean enabled) {
127+
setSetting(Setting.SHOULD_USE_COMPACT_RESPONSES, enabled);
128+
return this;
129+
}
130+
131+
/**
132+
* Which attributes should be returned if compact responses are disabled.
133+
* It works only if shouldUseCompactResponses is false. Defaults to "type,label" string.
134+
*
135+
* @param attrNames The comma-separated list of fields to return with each element.
136+
* @return self instance for chaining
137+
*/
138+
default HasAndroidSettings setElementResponseAttributes(String attrNames) {
139+
setSetting(Setting.ELEMENT_RESPONSE_ATTRIBUTES, attrNames);
140+
return this;
141+
}
142+
143+
/**
144+
* Set whether the source output/xpath search should consider all elements, visible and invisible.
145+
* Disabling this setting speeds up source and xml search. Works for UIAutomator2 only.
146+
*
147+
* @param enabled Either true or false. The default value if false.
148+
* @return self instance for chaining
149+
*/
150+
default HasAndroidSettings allowInvisibleElements(boolean enabled) {
151+
setSetting(Setting.ALLOW_INVISIBLE_ELEMENTS, enabled);
152+
return this;
153+
}
154+
155+
/**
156+
* Whether to enable or disable the notification listener.
157+
* No toast notifications are going to be added into page source output if
158+
* this setting is disabled.
159+
* Works for UIAutomator2 only.
160+
*
161+
* @param enabled Either true or false. The default value if true.
162+
* @return self instance for chaining
163+
*/
164+
default HasAndroidSettings enableNotificationListener(boolean enabled) {
165+
setSetting(Setting.ENABLE_NOTIFICATION_LISTENER, enabled);
166+
return this;
101167
}
102168
}

src/main/java/io/appium/java_client/ios/HasIOSSettings.java

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,77 @@
2222
interface HasIOSSettings extends HasSettings {
2323
/**
2424
* Set the `nativeWebTap` setting. *iOS-only method*.
25-
* Sets whether Safari/webviews should convert element taps into x/y taps
25+
* Sets whether Safari/webviews should convert element taps into x/y taps.
26+
*
2627
* @param enabled turns nativeWebTap on if true, off if false
28+
* @return self instance for chaining
2729
*/
28-
default void nativeWebTap(Boolean enabled) {
30+
default HasIOSSettings nativeWebTap(Boolean enabled) {
2931
setSetting(Setting.NATIVE_WEB_TAP, enabled);
32+
return this;
33+
}
34+
35+
/**
36+
* Whether to return compact (standards-compliant) and faster responses from find element/s
37+
* (the default setting). If set to false then the response may also contain other
38+
* available element attributes.
39+
*
40+
* @param enabled Either true or false. The default value if true.
41+
* @return self instance for chaining
42+
*/
43+
default HasIOSSettings setShouldUseCompactResponses(boolean enabled) {
44+
setSetting(Setting.SHOULD_USE_COMPACT_RESPONSES, enabled);
45+
return this;
46+
}
47+
48+
/**
49+
* Which attributes should be returned if compact responses are disabled.
50+
* It works only if shouldUseCompactResponses is set to false. Defaults to an empty string.
51+
*
52+
* @param attrNames The comma-separated list of fields to return with each element.
53+
* @return self instance for chaining
54+
*/
55+
default HasIOSSettings setElementResponseAttributes(String attrNames) {
56+
setSetting(Setting.ELEMENT_RESPONSE_ATTRIBUTES, attrNames);
57+
return this;
58+
}
59+
60+
/**
61+
* The quality of the screenshots generated by the screenshots broadcaster,
62+
* The value of 0 represents the maximum compression
63+
* (or lowest quality) while the value of 100 represents the least compression (or best quality).
64+
*
65+
* @param quality An integer in range 0..100. The default value is 25.
66+
* @return self instance for chaining
67+
*/
68+
default HasIOSSettings setMjpegServerScreenshotQuality(int quality) {
69+
setSetting(Setting.MJPEG_SERVER_SCREENSHOT_QUALITY, quality);
70+
return this;
71+
}
72+
73+
/**
74+
* The frame rate at which the background screenshots broadcaster should broadcast screenshots in range 1..60.
75+
* The default value is 10 (Frames Per Second).
76+
* Setting zero value will cause the frame rate to be at its maximum possible value.
77+
*
78+
* @param framerate An integer in range 1..60. The default value is 10.
79+
* @return self instance for chaining
80+
*/
81+
default HasIOSSettings setMjpegServerFramerate(int framerate) {
82+
setSetting(Setting.MJPEG_SERVER_FRAMERATE, framerate);
83+
return this;
84+
}
85+
86+
/**
87+
* Changes the quality of phone display screenshots according to XCTest/XCTImageQuality enum.
88+
* Sometimes setting this value to the maximum possible quality may crash XCTest because of
89+
* lack of the memory (lossless screenshot require more space).
90+
*
91+
* @param quality An integer in range 0..2. The default value is 1.
92+
* @return self instance for chaining
93+
*/
94+
default HasIOSSettings setScreenshotQuality(int quality) {
95+
setSetting(Setting.SCREENSHOT_QUALITY, quality);
96+
return this;
3097
}
3198
}

0 commit comments

Comments
 (0)