Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/io/appium/java_client/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

Expand All @@ -32,11 +32,13 @@ public enum Setting {
ENABLE_NOTIFICATION_LISTENER("enableNotificationListener"),
NORMALIZE_TAG_NAMES("normalizeTagNames"),
KEY_INJECTION_DELAY("keyInjectionDelay"),
SHUTDOWN_ON_POWER_DISCONNECT("shutdownOnPowerDisconnect"),
// iOS
MJPEG_SERVER_SCREENSHOT_QUALITY("mjpegServerScreenshotQuality"),
MJPEG_SERVER_FRAMERATE("mjpegServerFramerate"),
SCREENSHOT_QUALITY("screenshotQuality"),
NATIVE_WEB_TAP("nativeWebTap"),
MJPEG_SCALING_FACTOR("mjpegScalingFactor"),
// Android and iOS
SHOULD_USE_COMPACT_RESPONSES("shouldUseCompactResponses"),
ELEMENT_RESPONSE_ATTRIBUTES("elementResponseAttributes"),
Expand All @@ -46,7 +48,9 @@ public enum Setting {
FIX_IMAGE_FIND_SCREENSHOT_DIMENSIONS("fixImageFindScreenshotDims"),
FIX_IMAGE_TEMPLATE_SIZE("fixImageTemplateSize"),
CHECK_IMAGE_ELEMENT_STALENESS("checkForImageElementStaleness"),
UPDATE_IMAGE_ELEMENT_POSITION("autoUpdateImageElementPosition");
UPDATE_IMAGE_ELEMENT_POSITION("autoUpdateImageElementPosition"),
FIX_IMAGE_TEMPLATE_SCALE("fixImageTemplateScale"),
DEFAULT_IMAGE_TEMPLATE_SCALE("defaultImageTemplateScale");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ default HasAndroidSettings setShouldUseCompactResponses(boolean enabled) {

/**
* Which attributes should be returned if compact responses are disabled.
* It works only if shouldUseCompactResponses is false. Defaults to "type,label" string.
* It works only if shouldUseCompactResponses is false. Defaults to "" (empty string).
*
* @param attrNames The comma-separated list of fields to return with each element.
* @return self instance for chaining
Expand Down Expand Up @@ -165,4 +165,16 @@ default HasAndroidSettings enableNotificationListener(boolean enabled) {
setSetting(Setting.ENABLE_NOTIFICATION_LISTENER, enabled);
return this;
}

/**
* Whether to enable or disable shutdown the server through
* the broadcast receiver on ACTION_POWER_DISCONNECTED.
*
* @param enabled Either true or false. The default value if true.
* @return self instance for chaining
*/
default HasAndroidSettings shutdownOnPowerDisconnect(boolean enabled) {
setSetting(Setting.SHUTDOWN_ON_POWER_DISCONNECT, enabled);
return this;
}
}
14 changes: 13 additions & 1 deletion src/main/java/io/appium/java_client/ios/HasIOSSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ default HasIOSSettings setShouldUseCompactResponses(boolean enabled) {

/**
* Which attributes should be returned if compact responses are disabled.
* It works only if shouldUseCompactResponses is set to false. Defaults to an empty string.
* It works only if shouldUseCompactResponses is set to false. Defaults to "type,label" string.
*
* @param attrNames The comma-separated list of fields to return with each element.
* @return self instance for chaining
Expand Down Expand Up @@ -95,4 +95,16 @@ default HasIOSSettings setScreenshotQuality(int quality) {
setSetting(Setting.SCREENSHOT_QUALITY, quality);
return this;
}

/**
* The scale of screenshots in range 1..100.
* The default value is 100, no scaling
*
* @param scale An integer in range 1..100. The default value is 100.
* @return self instance for chaining
*/
default HasIOSSettings setMjpegScalingFactor(int scale) {
setSetting(Setting.MJPEG_SCALING_FACTOR, scale);
return this;
}
}
48 changes: 48 additions & 0 deletions src/test/java/io/appium/java_client/android/SettingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,54 @@ public class SettingTest extends BaseAndroidTest {
assertJSONElementContains(Setting.WAIT_FOR_SELECTOR_TIMEOUT, 1000);
}

@Test public void testNormalizeTagNames() {
assertEquals(false, driver.getSettings()
.get(Setting.NORMALIZE_TAG_NAMES.toString()));
driver.normalizeTagNames(true);
assertEquals(true, driver.getSettings()
.get(Setting.NORMALIZE_TAG_NAMES.toString()));
}

@Test public void testSetShouldUseCompactResponses() {
assertEquals(true, driver.getSettings()
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
driver.setShouldUseCompactResponses(false);
assertEquals(false, driver.getSettings()
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
}

@Test public void testSetElementResponseAttributes() {
assertEquals("", driver.getSettings()
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
driver.setElementResponseAttributes("type,label");
assertEquals("type,label", driver.getSettings()
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
}

@Test public void testAllowInvisibleElements() {
assertEquals(false, driver.getSettings()
.get(Setting.ALLOW_INVISIBLE_ELEMENTS.toString()));
driver.allowInvisibleElements(true);
assertEquals(true, driver.getSettings()
.get(Setting.ALLOW_INVISIBLE_ELEMENTS.toString()));
}

@Test public void testEnableNotificationListener() {
assertEquals(true, driver.getSettings()
.get(Setting.ENABLE_NOTIFICATION_LISTENER.toString()));
driver.enableNotificationListener(false);
assertEquals(false, driver.getSettings()
.get(Setting.ENABLE_NOTIFICATION_LISTENER.toString()));
}

@Test public void testShutdownOnPowerDisconnect() {
assertEquals(true, driver.getSettings()
.get(Setting.SHUTDOWN_ON_POWER_DISCONNECT.toString()));
driver.shutdownOnPowerDisconnect(false);
assertEquals(false, driver.getSettings()
.get(Setting.SHUTDOWN_ON_POWER_DISCONNECT.toString()));
}

private void assertJSONElementContains(Setting setting, long value) {
assertEquals(driver.getSettings().get(setting.toString()), value);
}
Expand Down
74 changes: 74 additions & 0 deletions src/test/java/io/appium/java_client/ios/SettingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client.ios;


import static org.junit.Assert.assertEquals;

import io.appium.java_client.Setting;
import org.junit.Test;

public class SettingTest extends AppIOSTest {

@Test public void testSetShouldUseCompactResponses() {
assertEquals(true, driver.getSettings()
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
driver.setShouldUseCompactResponses(false);
assertEquals(false, driver.getSettings()
.get(Setting.SHOULD_USE_COMPACT_RESPONSES.toString()));
}

@Test public void testSetElementResponseAttributes() {
assertEquals("type,label", driver.getSettings()
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
driver.setElementResponseAttributes("name");
assertEquals("name", driver.getSettings()
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
}

@Test public void testSetMjpegServerScreenshotQuality() {
assertEquals(25L, driver.getSettings()
.get(Setting.MJPEG_SERVER_SCREENSHOT_QUALITY.toString()));
driver.setMjpegServerScreenshotQuality(0);
assertEquals(0L, driver.getSettings()
.get(Setting.MJPEG_SERVER_SCREENSHOT_QUALITY.toString()));
}

@Test public void testSetMjpegServerFramerate() {
assertEquals(10L, driver.getSettings()
.get(Setting.MJPEG_SERVER_FRAMERATE.toString()));
driver.setMjpegServerFramerate(60);
assertEquals(60L, driver.getSettings()
.get(Setting.MJPEG_SERVER_FRAMERATE.toString()));
}

@Test public void testSetScreenshotQuality() {
assertEquals(1L, driver.getSettings()
.get(Setting.SCREENSHOT_QUALITY.toString()));
driver.setScreenshotQuality(2);
assertEquals(2L, driver.getSettings()
.get(Setting.SCREENSHOT_QUALITY.toString()));
}

@Test public void testSetMjpegScalingFactor() {
driver.setMjpegScalingFactor(1);
assertEquals(1L, driver.getSettings()
.get(Setting.MJPEG_SCALING_FACTOR.toString()));
}


}