未验证 提交 c4060efb 编写于 作者: V Valery Yatsynovich 提交者: GitHub

feat: Add ability to set multiple settings (#1409)

上级 5999cebe
......@@ -21,7 +21,10 @@ import static io.appium.java_client.MobileCommand.setSettingsCommand;
import org.openqa.selenium.remote.Response;
import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
public interface HasSettings extends ExecutesMethod {
......@@ -52,6 +55,31 @@ public interface HasSettings extends ExecutesMethod {
return this;
}
/**
* Sets settings for this test session.
*
* @param settings a map with settings, where key is the setting name you wish to set and value is the value of
* the setting.
* @return Self instance for chaining.
*/
default HasSettings setSettings(EnumMap<Setting, Object> settings) {
Map<String, Object> convertedSettings = settings.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey().toString(), Entry::getValue));
return setSettings(convertedSettings);
}
/**
* Sets settings for this test session.
*
* @param settings a map with settings, where key is the setting name you wish to set and value is the value of
* the setting.
* @return Self instance for chaining.
*/
default HasSettings setSettings(Map<String, Object> settings) {
CommandExecutionHelper.execute(this, setSettingsCommand(settings));
return this;
}
/**
* Get settings stored for this test session It's probably better to use a
* convenience function, rather than use this function directly. Try finding
......
......@@ -481,8 +481,11 @@ public class MobileCommand {
}
public static Map.Entry<String, Map<String, ?>> setSettingsCommand(String setting, Object value) {
return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings",
prepareArguments(setting, value)));
return setSettingsCommand(prepareArguments(setting, value));
}
public static Map.Entry<String, Map<String, ?>> setSettingsCommand(Map<String, Object> settings) {
return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings", settings));
}
/**
......
......@@ -4,6 +4,9 @@ import io.appium.java_client.Setting;
import org.junit.Test;
import java.time.Duration;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
......@@ -103,6 +106,24 @@ public class SettingTest extends BaseAndroidTest {
.get("shouldUseCompactResponses"));
}
@Test public void setMultipleSettings() {
EnumMap<Setting, Object> enumSettings = new EnumMap<>(Setting.class);
enumSettings.put(Setting.IGNORE_UNIMPORTANT_VIEWS, true);
enumSettings.put(Setting.ELEMENT_RESPONSE_ATTRIBUTES, "type,label");
driver.setSettings(enumSettings);
Map<String, Object> actual = driver.getSettings();
assertEquals(true, actual.get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString()));
assertEquals("type,label", actual.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
Map<String, Object> mapSettings = new HashMap<>();
mapSettings.put(Setting.IGNORE_UNIMPORTANT_VIEWS.toString(), false);
mapSettings.put(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString(), "");
driver.setSettings(mapSettings);
actual = driver.getSettings();
assertEquals(false, actual.get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString()));
assertEquals("", actual.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
}
private void assertJSONElementContains(Setting setting, long value) {
assertEquals(driver.getSettings().get(setting.toString()), value);
}
......
......@@ -22,6 +22,9 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
public class SettingTest extends AppIOSTest {
......@@ -34,10 +37,10 @@ public class SettingTest extends AppIOSTest {
}
@Test public void testSetElementResponseAttributes() {
assertEquals("type,label", driver.getSettings()
assertEquals("", driver.getSettings()
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
driver.setElementResponseAttributes("name");
assertEquals("name", driver.getSettings()
driver.setElementResponseAttributes("type,label");
assertEquals("type,label", driver.getSettings()
.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
}
......@@ -94,5 +97,21 @@ public class SettingTest extends AppIOSTest {
.get("shouldUseCompactResponses"));
}
@Test public void setMultipleSettings() {
EnumMap<Setting, Object> enumSettings = new EnumMap<>(Setting.class);
enumSettings.put(Setting.IGNORE_UNIMPORTANT_VIEWS, true);
enumSettings.put(Setting.ELEMENT_RESPONSE_ATTRIBUTES, "type,label");
driver.setSettings(enumSettings);
Map<String, Object> actual = driver.getSettings();
assertEquals(true, actual.get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString()));
assertEquals("type,label", actual.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
Map<String, Object> mapSettings = new HashMap<>();
mapSettings.put(Setting.IGNORE_UNIMPORTANT_VIEWS.toString(), false);
mapSettings.put(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString(), "");
driver.setSettings(mapSettings);
actual = driver.getSettings();
assertEquals(false, actual.get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString()));
assertEquals("", actual.get(Setting.ELEMENT_RESPONSE_ATTRIBUTES.toString()));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册