From 6ae4166d7cfb067743e4f49894be55d3e8db2d37 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Fri, 16 Jun 2017 15:43:07 -0700 Subject: [PATCH 1/4] enable nativeWebTap setting for iOS --- .../io/appium/java_client/HasSettings.java | 57 +++++++++++++++++++ .../io/appium/java_client/MobileCommand.java | 9 +++ .../java_client/{android => }/Setting.java | 5 +- .../java_client/android/AndroidDriver.java | 2 +- .../android/AndroidMobileCommandHelper.java | 9 --- ...sSettings.java => HasAndroidSettings.java} | 41 +------------ .../java_client/ios/HasIOSSettings.java | 32 +++++++++++ .../io/appium/java_client/ios/IOSDriver.java | 2 +- 8 files changed, 106 insertions(+), 51 deletions(-) create mode 100644 src/main/java/io/appium/java_client/HasSettings.java rename src/main/java/io/appium/java_client/{android => }/Setting.java (91%) rename src/main/java/io/appium/java_client/android/{HasSettings.java => HasAndroidSettings.java} (78%) create mode 100644 src/main/java/io/appium/java_client/ios/HasIOSSettings.java diff --git a/src/main/java/io/appium/java_client/HasSettings.java b/src/main/java/io/appium/java_client/HasSettings.java new file mode 100644 index 000000000..de7c0bbde --- /dev/null +++ b/src/main/java/io/appium/java_client/HasSettings.java @@ -0,0 +1,57 @@ +/* + * 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; + +import com.google.common.collect.ImmutableMap; + +import org.openqa.selenium.remote.Response; + +import java.util.Map; + +import static io.appium.java_client.MobileCommand.getSettingsCommand; +import static io.appium.java_client.MobileCommand.setSettingsCommand; + +public interface HasSettings extends ExecutesMethod { + + /** + * Set a setting for this test session It's probably better to use a + * convenience function, rather than use this function directly. Try finding + * the method for the specific setting you want to change. + * + * @param setting Setting you wish to set. + * @param value value of the setting. + */ + default void setSetting(Setting setting, Object value) { + CommandExecutionHelper.execute(this, setSettingsCommand(setting, value)); + } + + /** + * Get settings stored for this test session It's probably better to use a + * convenience function, rather than use this function directly. Try finding + * the method for the specific setting you want to read. + * + * @return JsonObject, a straight-up hash of settings. + */ + @SuppressWarnings("unchecked") + default Map getSettings() { + Map.Entry> keyValuePair = getSettingsCommand(); + Response response = execute(keyValuePair.getKey(), keyValuePair.getValue()); + + return ImmutableMap.builder() + .putAll(Map.class.cast(response.getValue())).build(); + } +} diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 01acadbda..85ea4f4ff 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -354,4 +354,13 @@ public static ImmutableMap prepareArguments(String[] params, return new AbstractMap.SimpleEntry<>( LOCK, prepareArguments("seconds", duration.getSeconds())); } + + public static Map.Entry> getSettingsCommand() { + return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.of()); + } + + public static Map.Entry> setSettingsCommand(Setting setting, Object value) { + return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings", + prepareArguments(setting.toString(), value))); + } } diff --git a/src/main/java/io/appium/java_client/android/Setting.java b/src/main/java/io/appium/java_client/Setting.java similarity index 91% rename from src/main/java/io/appium/java_client/android/Setting.java rename to src/main/java/io/appium/java_client/Setting.java index 88ce6829e..e88acc714 100644 --- a/src/main/java/io/appium/java_client/android/Setting.java +++ b/src/main/java/io/appium/java_client/Setting.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.appium.java_client.android; +package io.appium.java_client; /** * Enums defining constants for Appium Settings which can be set and toggled during a test session. @@ -26,7 +26,8 @@ public enum Setting { WAIT_FOR_SELECTOR_TIMEOUT("setWaitForSelectorTimeout"), WAIT_SCROLL_ACKNOWLEDGMENT_TIMEOUT("setScrollAcknowledgmentTimeout"), WAIT_ACTION_ACKNOWLEDGMENT_TIMEOUT("setActionAcknowledgmentTimeout"), - KEY_INJECTION_DELAY("setKeyInjectionDelay"); + KEY_INJECTION_DELAY("setKeyInjectionDelay"), + NATIVE_WEB_TAP("nativeWebTap"); private String name; diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 7913ec52c..46c770093 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -47,7 +47,7 @@ public class AndroidDriver extends AppiumDriver implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity, - FindsByAndroidUIAutomator, LocksAndroidDevice, HasSettings, HasDeviceDetails, + FindsByAndroidUIAutomator, LocksAndroidDevice, HasAndroidSettings, HasDeviceDetails, HasSupportedPerformanceDataType { private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID; diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java index 55eae2f9d..d00930eaa 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -355,13 +355,4 @@ public class AndroidMobileCommandHelper extends MobileCommand { return new AbstractMap.SimpleEntry<>( REPLACE_VALUE, prepareArguments(parameters, values)); } - - public static Map.Entry> getSettingsCommand() { - return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.of()); - } - - public static Map.Entry> setSettingsCommand(Setting setting, Object value) { - return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings", - prepareArguments(setting.toString(), value))); - } } diff --git a/src/main/java/io/appium/java_client/android/HasSettings.java b/src/main/java/io/appium/java_client/android/HasAndroidSettings.java similarity index 78% rename from src/main/java/io/appium/java_client/android/HasSettings.java rename to src/main/java/io/appium/java_client/android/HasAndroidSettings.java index 9c3311cb5..4550c8a4f 100644 --- a/src/main/java/io/appium/java_client/android/HasSettings.java +++ b/src/main/java/io/appium/java_client/android/HasAndroidSettings.java @@ -16,48 +16,13 @@ package io.appium.java_client.android; -import static io.appium.java_client.android.AndroidMobileCommandHelper.getSettingsCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.setSettingsCommand; -import com.google.common.collect.ImmutableMap; - -import io.appium.java_client.CommandExecutionHelper; -import io.appium.java_client.ExecutesMethod; - -import org.openqa.selenium.remote.Response; +import io.appium.java_client.HasSettings; +import io.appium.java_client.Setting; import java.time.Duration; -import java.util.Map; - -interface HasSettings extends ExecutesMethod { - /** - * Set a setting for this test session It's probably better to use a - * convenience function, rather than use this function directly. Try finding - * the method for the specific setting you want to change. - * - * @param setting Setting you wish to set. - * @param value value of the setting. - */ - default void setSetting(Setting setting, Object value) { - CommandExecutionHelper.execute(this, setSettingsCommand(setting, value)); - } - - /** - * Get settings stored for this test session It's probably better to use a - * convenience function, rather than use this function directly. Try finding - * the method for the specific setting you want to read. - * - * @return JsonObject, a straight-up hash of settings. - */ - @SuppressWarnings("unchecked") - default Map getSettings() { - Map.Entry> keyValuePair = getSettingsCommand(); - Response response = execute(keyValuePair.getKey(), keyValuePair.getValue()); - - return ImmutableMap.builder() - .putAll(Map.class.cast(response.getValue())).build(); - } +interface HasAndroidSettings extends HasSettings { /** * Set the `ignoreUnimportantViews` setting. *Android-only method*. * Sets whether Android devices should use `setCompressedLayoutHeirarchy()` diff --git a/src/main/java/io/appium/java_client/ios/HasIOSSettings.java b/src/main/java/io/appium/java_client/ios/HasIOSSettings.java new file mode 100644 index 000000000..f6050923a --- /dev/null +++ b/src/main/java/io/appium/java_client/ios/HasIOSSettings.java @@ -0,0 +1,32 @@ +/* + * 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 io.appium.java_client.HasSettings; +import io.appium.java_client.Setting; + +interface HasIOSSettings extends HasSettings { + /** + * Set the `nativeWebTap` setting. *iOS-only method*. + * Sets whether Safari/webviews should convert element taps into x/y taps + * @param enabled turns nativeWebTap on if true, off if false + */ + default void nativeWebTap(Boolean enabled) { + setSetting(Setting.NATIVE_WEB_TAP, enabled); + } +} diff --git a/src/main/java/io/appium/java_client/ios/IOSDriver.java b/src/main/java/io/appium/java_client/ios/IOSDriver.java index 948232fbd..394b09ab4 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -51,7 +51,7 @@ */ public class IOSDriver extends AppiumDriver - implements HidesKeyboardWithKeyName, ShakesDevice, + implements HidesKeyboardWithKeyName, ShakesDevice, HasIOSSettings, FindsByIosUIAutomation, LocksIOSDevice, PerformsTouchID, FindsByIosNSPredicate, FindsByIosClassChain { From 56260a070e8aa7dcaf6d95fc17cf1773d0a808c6 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Fri, 16 Jun 2017 16:22:14 -0700 Subject: [PATCH 2/4] add tests for nativeWebTap method --- .../java_client/android/SettingTest.java | 1 + .../java_client/ios/BaseSafariTest.java | 46 +++++++++++++++++++ .../ios/IOSNativeWebTapSettingTest.java | 27 +++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/test/java/io/appium/java_client/ios/BaseSafariTest.java create mode 100644 src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java diff --git a/src/test/java/io/appium/java_client/android/SettingTest.java b/src/test/java/io/appium/java_client/android/SettingTest.java index a539f9371..9680eafb2 100644 --- a/src/test/java/io/appium/java_client/android/SettingTest.java +++ b/src/test/java/io/appium/java_client/android/SettingTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; +import io.appium.java_client.Setting; import org.junit.Test; import java.time.Duration; diff --git a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java b/src/test/java/io/appium/java_client/ios/BaseSafariTest.java new file mode 100644 index 000000000..75489f651 --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/BaseSafariTest.java @@ -0,0 +1,46 @@ +/* + * 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 io.appium.java_client.remote.AutomationName; +import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; +import org.junit.BeforeClass; +import org.openqa.selenium.remote.DesiredCapabilities; + +public class BaseSafariTest extends BaseIOSTest { + + @BeforeClass public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!"); + } + + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari"); + capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.2"); + //sometimes environment has performance problems + capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + driver = new IOSDriver<>(service.getUrl(), capabilities); + } +} diff --git a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java new file mode 100644 index 000000000..a7e770222 --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java @@ -0,0 +1,27 @@ +package io.appium.java_client.ios; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +public class IOSNativeWebTapSettingTest extends BaseSafariTest { + + @Test public void nativeWebTapSettingTest() throws InterruptedException { + driver.get("https://saucelabs.com/test/guinea-pig"); + + // do a click with nativeWebTap turned on, and assert we get to the right page + driver.nativeWebTap(true); + WebElement el = driver.findElementById("i am a link"); + el.click(); + assertEquals(true, driver.getTitle().contains("I am another page title")); + driver.navigate().back(); + + // now do a click with it turned off and assert the same behavior + assertEquals(true, driver.getTitle().contains("I am a page title")); + driver.nativeWebTap(false); + el = driver.findElementById("i am a link"); + el.click(); + assertEquals(true, driver.getTitle().contains("I am another page title")); + } +} From bbfa335a817146f68e46aa7be74bd187a21fff42 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Fri, 16 Jun 2017 16:27:52 -0700 Subject: [PATCH 3/4] make javadoc happy --- src/main/java/io/appium/java_client/AppiumSetting.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/appium/java_client/AppiumSetting.java b/src/main/java/io/appium/java_client/AppiumSetting.java index 9fcf32f79..c347f787f 100644 --- a/src/main/java/io/appium/java_client/AppiumSetting.java +++ b/src/main/java/io/appium/java_client/AppiumSetting.java @@ -19,7 +19,7 @@ /** * This enum is deprecated. Was moved to - * {@link io.appium.java_client.android.Setting}. + * {@link io.appium.java_client.Setting}. */ @Deprecated public enum AppiumSetting { From 6714c1abfc95ade83978560649e76aabc78da4d5 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Fri, 16 Jun 2017 16:39:51 -0700 Subject: [PATCH 4/4] conform to style --- .../io/appium/java_client/HasSettings.java | 5 ++-- .../java_client/ios/BaseSafariTest.java | 30 +++++++++---------- .../ios/IOSNativeWebTapSettingTest.java | 30 +++++++++---------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main/java/io/appium/java_client/HasSettings.java b/src/main/java/io/appium/java_client/HasSettings.java index de7c0bbde..3195bcf58 100644 --- a/src/main/java/io/appium/java_client/HasSettings.java +++ b/src/main/java/io/appium/java_client/HasSettings.java @@ -16,14 +16,15 @@ package io.appium.java_client; +import static io.appium.java_client.MobileCommand.getSettingsCommand; +import static io.appium.java_client.MobileCommand.setSettingsCommand; + import com.google.common.collect.ImmutableMap; import org.openqa.selenium.remote.Response; import java.util.Map; -import static io.appium.java_client.MobileCommand.getSettingsCommand; -import static io.appium.java_client.MobileCommand.setSettingsCommand; public interface HasSettings extends ExecutesMethod { diff --git a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java b/src/test/java/io/appium/java_client/ios/BaseSafariTest.java index 75489f651..bca6468a3 100644 --- a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseSafariTest.java @@ -26,21 +26,21 @@ public class BaseSafariTest extends BaseIOSTest { - @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); + @BeforeClass public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); - if (service == null || !service.isRunning()) { - throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!"); - } + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!"); + } - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari"); - capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.2"); - //sometimes environment has performance problems - capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); - driver = new IOSDriver<>(service.getUrl(), capabilities); - } + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari"); + capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.2"); + //sometimes environment has performance problems + capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + driver = new IOSDriver<>(service.getUrl(), capabilities); + } } diff --git a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java index a7e770222..1369d3d5b 100644 --- a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java @@ -7,21 +7,21 @@ public class IOSNativeWebTapSettingTest extends BaseSafariTest { - @Test public void nativeWebTapSettingTest() throws InterruptedException { - driver.get("https://saucelabs.com/test/guinea-pig"); + @Test public void nativeWebTapSettingTest() throws InterruptedException { + driver.get("https://saucelabs.com/test/guinea-pig"); - // do a click with nativeWebTap turned on, and assert we get to the right page - driver.nativeWebTap(true); - WebElement el = driver.findElementById("i am a link"); - el.click(); - assertEquals(true, driver.getTitle().contains("I am another page title")); - driver.navigate().back(); + // do a click with nativeWebTap turned on, and assert we get to the right page + driver.nativeWebTap(true); + WebElement el = driver.findElementById("i am a link"); + el.click(); + assertEquals(true, driver.getTitle().contains("I am another page title")); + driver.navigate().back(); - // now do a click with it turned off and assert the same behavior - assertEquals(true, driver.getTitle().contains("I am a page title")); - driver.nativeWebTap(false); - el = driver.findElementById("i am a link"); - el.click(); - assertEquals(true, driver.getTitle().contains("I am another page title")); - } + // now do a click with it turned off and assert the same behavior + assertEquals(true, driver.getTitle().contains("I am a page title")); + driver.nativeWebTap(false); + el = driver.findElementById("i am a link"); + el.click(); + assertEquals(true, driver.getTitle().contains("I am another page title")); + } }