Skip to content

Commit 1aac740

Browse files
takeyaqamykola-mokhnach
authored andcommitted
add the missing setting which introduced in appium 1.12 and 1.13 (#1156)
1 parent bbd63af commit 1aac740

File tree

5 files changed

+154
-4
lines changed

5 files changed

+154
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
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/
21+
* https://appium.io/docs/en/advanced-concepts/settings/
2222
*/
2323
public enum Setting {
2424

@@ -32,11 +32,13 @@ public enum Setting {
3232
ENABLE_NOTIFICATION_LISTENER("enableNotificationListener"),
3333
NORMALIZE_TAG_NAMES("normalizeTagNames"),
3434
KEY_INJECTION_DELAY("keyInjectionDelay"),
35+
SHUTDOWN_ON_POWER_DISCONNECT("shutdownOnPowerDisconnect"),
3536
// iOS
3637
MJPEG_SERVER_SCREENSHOT_QUALITY("mjpegServerScreenshotQuality"),
3738
MJPEG_SERVER_FRAMERATE("mjpegServerFramerate"),
3839
SCREENSHOT_QUALITY("screenshotQuality"),
3940
NATIVE_WEB_TAP("nativeWebTap"),
41+
MJPEG_SCALING_FACTOR("mjpegScalingFactor"),
4042
// Android and iOS
4143
SHOULD_USE_COMPACT_RESPONSES("shouldUseCompactResponses"),
4244
ELEMENT_RESPONSE_ATTRIBUTES("elementResponseAttributes"),
@@ -46,7 +48,9 @@ public enum Setting {
4648
FIX_IMAGE_FIND_SCREENSHOT_DIMENSIONS("fixImageFindScreenshotDims"),
4749
FIX_IMAGE_TEMPLATE_SIZE("fixImageTemplateSize"),
4850
CHECK_IMAGE_ELEMENT_STALENESS("checkForImageElementStaleness"),
49-
UPDATE_IMAGE_ELEMENT_POSITION("autoUpdateImageElementPosition");
51+
UPDATE_IMAGE_ELEMENT_POSITION("autoUpdateImageElementPosition"),
52+
FIX_IMAGE_TEMPLATE_SCALE("fixImageTemplateScale"),
53+
DEFAULT_IMAGE_TEMPLATE_SCALE("defaultImageTemplateScale");
5054

5155
private final String name;
5256

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ default HasAndroidSettings setShouldUseCompactResponses(boolean enabled) {
130130

131131
/**
132132
* Which attributes should be returned if compact responses are disabled.
133-
* It works only if shouldUseCompactResponses is false. Defaults to "type,label" string.
133+
* It works only if shouldUseCompactResponses is false. Defaults to "" (empty string).
134134
*
135135
* @param attrNames The comma-separated list of fields to return with each element.
136136
* @return self instance for chaining
@@ -165,4 +165,16 @@ default HasAndroidSettings enableNotificationListener(boolean enabled) {
165165
setSetting(Setting.ENABLE_NOTIFICATION_LISTENER, enabled);
166166
return this;
167167
}
168+
169+
/**
170+
* Whether to enable or disable shutdown the server through
171+
* the broadcast receiver on ACTION_POWER_DISCONNECTED.
172+
*
173+
* @param enabled Either true or false. The default value if true.
174+
* @return self instance for chaining
175+
*/
176+
default HasAndroidSettings shutdownOnPowerDisconnect(boolean enabled) {
177+
setSetting(Setting.SHUTDOWN_ON_POWER_DISCONNECT, enabled);
178+
return this;
179+
}
168180
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ default HasIOSSettings setShouldUseCompactResponses(boolean enabled) {
4747

4848
/**
4949
* 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.
50+
* It works only if shouldUseCompactResponses is set to false. Defaults to "type,label" string.
5151
*
5252
* @param attrNames The comma-separated list of fields to return with each element.
5353
* @return self instance for chaining
@@ -95,4 +95,16 @@ default HasIOSSettings setScreenshotQuality(int quality) {
9595
setSetting(Setting.SCREENSHOT_QUALITY, quality);
9696
return this;
9797
}
98+
99+
/**
100+
* The scale of screenshots in range 1..100.
101+
* The default value is 100, no scaling
102+
*
103+
* @param scale An integer in range 1..100. The default value is 100.
104+
* @return self instance for chaining
105+
*/
106+
default HasIOSSettings setMjpegScalingFactor(int scale) {
107+
setSetting(Setting.MJPEG_SCALING_FACTOR, scale);
108+
return this;
109+
}
98110
}

src/test/java/io/appium/java_client/android/SettingTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,54 @@ public class SettingTest extends BaseAndroidTest {
3636
assertJSONElementContains(Setting.WAIT_FOR_SELECTOR_TIMEOUT, 1000);
3737
}
3838

39+
@Test public void testNormalizeTagNames() {
40+
assertEquals(false, driver.getSettings()
41+
.get(Setting.NORMALIZE_TAG_NAMES.toString()));
42+
driver.normalizeTagNames(true);
43+
assertEquals(true, driver.getSettings()
44+
.get(Setting.NORMALIZE_TAG_NAMES.toString()));
45+
}
46+
47+
@Test public void testSetShouldUseCompactResponses() {
48+
assertEquals(true, driver.getSettings()
49+
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
50+
driver.setShouldUseCompactResponses(false);
51+
assertEquals(false, driver.getSettings()
52+
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
53+
}
54+
55+
@Test public void testSetElementResponseAttributes() {
56+
assertEquals("", driver.getSettings()
57+
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
58+
driver.setElementResponseAttributes("type,label");
59+
assertEquals("type,label", driver.getSettings()
60+
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
61+
}
62+
63+
@Test public void testAllowInvisibleElements() {
64+
assertEquals(false, driver.getSettings()
65+
.get(Setting.ALLOW_INVISIBLE_ELEMENTS.toString()));
66+
driver.allowInvisibleElements(true);
67+
assertEquals(true, driver.getSettings()
68+
.get(Setting.ALLOW_INVISIBLE_ELEMENTS.toString()));
69+
}
70+
71+
@Test public void testEnableNotificationListener() {
72+
assertEquals(true, driver.getSettings()
73+
.get(Setting.ENABLE_NOTIFICATION_LISTENER.toString()));
74+
driver.enableNotificationListener(false);
75+
assertEquals(false, driver.getSettings()
76+
.get(Setting.ENABLE_NOTIFICATION_LISTENER.toString()));
77+
}
78+
79+
@Test public void testShutdownOnPowerDisconnect() {
80+
assertEquals(true, driver.getSettings()
81+
.get(Setting.SHUTDOWN_ON_POWER_DISCONNECT.toString()));
82+
driver.shutdownOnPowerDisconnect(false);
83+
assertEquals(false, driver.getSettings()
84+
.get(Setting.SHUTDOWN_ON_POWER_DISCONNECT.toString()));
85+
}
86+
3987
private void assertJSONElementContains(Setting setting, long value) {
4088
assertEquals(driver.getSettings().get(setting.toString()), value);
4189
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.ios;
18+
19+
20+
import static org.junit.Assert.assertEquals;
21+
22+
import io.appium.java_client.Setting;
23+
import org.junit.Test;
24+
25+
public class SettingTest extends AppIOSTest {
26+
27+
@Test public void testSetShouldUseCompactResponses() {
28+
assertEquals(true, driver.getSettings()
29+
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
30+
driver.setShouldUseCompactResponses(false);
31+
assertEquals(false, driver.getSettings()
32+
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
33+
}
34+
35+
@Test public void testSetElementResponseAttributes() {
36+
assertEquals("type,label", driver.getSettings()
37+
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
38+
driver.setElementResponseAttributes("name");
39+
assertEquals("name", driver.getSettings()
40+
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
41+
}
42+
43+
@Test public void testSetMjpegServerScreenshotQuality() {
44+
assertEquals(25L, driver.getSettings()
45+
.get(Setting.MJPEG_SERVER_SCREENSHOT_QUALITY.toString()));
46+
driver.setMjpegServerScreenshotQuality(0);
47+
assertEquals(0L, driver.getSettings()
48+
.get(Setting.MJPEG_SERVER_SCREENSHOT_QUALITY.toString()));
49+
}
50+
51+
@Test public void testSetMjpegServerFramerate() {
52+
assertEquals(10L, driver.getSettings()
53+
.get(Setting.MJPEG_SERVER_FRAMERATE.toString()));
54+
driver.setMjpegServerFramerate(60);
55+
assertEquals(60L, driver.getSettings()
56+
.get(Setting.MJPEG_SERVER_FRAMERATE.toString()));
57+
}
58+
59+
@Test public void testSetScreenshotQuality() {
60+
assertEquals(1L, driver.getSettings()
61+
.get(Setting.SCREENSHOT_QUALITY.toString()));
62+
driver.setScreenshotQuality(2);
63+
assertEquals(2L, driver.getSettings()
64+
.get(Setting.SCREENSHOT_QUALITY.toString()));
65+
}
66+
67+
@Test public void testSetMjpegScalingFactor() {
68+
driver.setMjpegScalingFactor(1);
69+
assertEquals(1L, driver.getSettings()
70+
.get(Setting.MJPEG_SCALING_FACTOR.toString()));
71+
}
72+
73+
74+
}

0 commit comments

Comments
 (0)