From c559326686f0ce8f0679264357372e012b616d02 Mon Sep 17 00:00:00 2001 From: Ajeesh Date: Fri, 24 May 2019 18:18:48 -0700 Subject: [PATCH 001/675] Add apple tvOS platform constant (#1142) * tvOS driver implementation * clean up * removed tvos driver --- src/main/java/io/appium/java_client/remote/MobilePlatform.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/appium/java_client/remote/MobilePlatform.java b/src/main/java/io/appium/java_client/remote/MobilePlatform.java index c14a1b4e6..07ecc8223 100644 --- a/src/main/java/io/appium/java_client/remote/MobilePlatform.java +++ b/src/main/java/io/appium/java_client/remote/MobilePlatform.java @@ -22,4 +22,5 @@ public interface MobilePlatform { String IOS = "iOS"; String FIREFOX_OS = "FirefoxOS"; String WINDOWS = "Windows"; + String TVOS = "tvOS"; } From bbd63aff74b71902e4d2afd0fc163a19dd3d29fa Mon Sep 17 00:00:00 2001 From: Takeshi Kishi Date: Tue, 4 Jun 2019 23:05:06 +0900 Subject: [PATCH 002/675] delete nonexistent class from DefaultAspect (#1149) --- src/main/java/io/appium/java_client/events/DefaultAspect.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/appium/java_client/events/DefaultAspect.java b/src/main/java/io/appium/java_client/events/DefaultAspect.java index b5cf9f280..6e0aaf5c4 100644 --- a/src/main/java/io/appium/java_client/events/DefaultAspect.java +++ b/src/main/java/io/appium/java_client/events/DefaultAspect.java @@ -99,7 +99,6 @@ class DefaultAspect { + "execution(* org.openqa.selenium.ContextAware.*(..)) || " + "execution(* io.appium.java_client.FindsByAccessibilityId.*(..)) || " + "execution(* io.appium.java_client.FindsByAndroidUIAutomator.*(..)) || " - + "execution(* io.appium.java_client.FindsByIosUIAutomation.*(..)) || " + "execution(* io.appium.java_client.FindsByWindowsAutomation.*(..)) || " + "execution(* io.appium.java_client.FindsByIosNSPredicate.*(..)) || " + "execution(* org.openqa.selenium.internal.FindsByClassName.*(..)) || " From 1aac740f4857b88e94e5dc2a8e1a22c8e79e6d2e Mon Sep 17 00:00:00 2001 From: Takeshi Kishi Date: Fri, 14 Jun 2019 15:17:23 +0900 Subject: [PATCH 003/675] add the missing setting which introduced in appium 1.12 and 1.13 (#1156) --- .../java/io/appium/java_client/Setting.java | 8 +- .../android/HasAndroidSettings.java | 14 +++- .../java_client/ios/HasIOSSettings.java | 14 +++- .../java_client/android/SettingTest.java | 48 ++++++++++++ .../appium/java_client/ios/SettingTest.java | 74 +++++++++++++++++++ 5 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 src/test/java/io/appium/java_client/ios/SettingTest.java diff --git a/src/main/java/io/appium/java_client/Setting.java b/src/main/java/io/appium/java_client/Setting.java index 10e25b5fb..316015600 100644 --- a/src/main/java/io/appium/java_client/Setting.java +++ b/src/main/java/io/appium/java_client/Setting.java @@ -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 { @@ -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"), @@ -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; diff --git a/src/main/java/io/appium/java_client/android/HasAndroidSettings.java b/src/main/java/io/appium/java_client/android/HasAndroidSettings.java index b77630b40..a3584c614 100644 --- a/src/main/java/io/appium/java_client/android/HasAndroidSettings.java +++ b/src/main/java/io/appium/java_client/android/HasAndroidSettings.java @@ -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 @@ -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; + } } diff --git a/src/main/java/io/appium/java_client/ios/HasIOSSettings.java b/src/main/java/io/appium/java_client/ios/HasIOSSettings.java index b43bae997..ad8179cdb 100644 --- a/src/main/java/io/appium/java_client/ios/HasIOSSettings.java +++ b/src/main/java/io/appium/java_client/ios/HasIOSSettings.java @@ -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 @@ -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; + } } 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 9680eafb2..bf93da2df 100644 --- a/src/test/java/io/appium/java_client/android/SettingTest.java +++ b/src/test/java/io/appium/java_client/android/SettingTest.java @@ -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); } diff --git a/src/test/java/io/appium/java_client/ios/SettingTest.java b/src/test/java/io/appium/java_client/ios/SettingTest.java new file mode 100644 index 000000000..a93f1ff1c --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/SettingTest.java @@ -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())); + } + + +} From 864c2ed28db68ba131941ea1499ddfa731c2f839 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 16 Jun 2019 13:29:33 +0200 Subject: [PATCH 004/675] Update CI scripts (#1157) --- .travis.yml | 20 +--- azure-pipelines.yml | 25 ++-- google-style.xml | 5 - .../java_client/android/SettingTest.java | 4 +- .../generation/BaseElementGenerationTest.java | 26 ++-- .../android/AndroidElementGeneratingTest.java | 48 ++++---- .../ios/IOSElementGenerationTest.java | 111 +++++++++--------- .../appium/java_client/ios/BaseIOSTest.java | 11 +- .../java_client/ios/BaseSafariTest.java | 3 +- .../java_client/ios/IOSElementTest.java | 12 +- .../appium/java_client/ios/SettingTest.java | 5 +- .../service/local/StartingAppLocallyTest.java | 21 ++-- 12 files changed, 142 insertions(+), 149 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59f45de5a..3af8d0a80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,26 +16,8 @@ matrix: components: - extra-android-support - sys-img-armeabi-v7a-android-24 - before_install: - - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash - - nvm install 8 - - node --version - - npm --version - - npm install -g $appiumVersion - - echo y | android update sdk -a --no-ui --filter android-24 - - echo y | android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-24 - - android list targets | grep -E '^id:' | awk -F '"' '{$1=""; print $2}' # list all targets - - echo no | android create avd --force -n test -t android-24 --abi armeabi-v7a - - emulator -avd test -no-skin -no-window & - - android-wait-for-emulator - - adb shell input keyevent 82 & - - adb wait-for-device get-serialno - - sleep 100 - - chmod +x gradlew - - ./gradlew --version - - echo y |adb devices script: - - ./gradlew clean build uiAutomationTest -x test -x signArchives + - ./gradlew clean build -x signArchives -x test -x checkstyleTest before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9395f8cb2..2aaa45a52 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -4,22 +4,26 @@ # https://docs.microsoft.com/azure/devops/pipelines/languages/java pool: - vmImage: 'macOS 10.13' + vmImage: 'macOS 10.14' variables: ANDROID_EMU_NAME: test ANDROID_EMU_ABI: x86 ANDROID_EMU_TARGET: android-27 + ANDROID_EMU_TAG: google_apis + XCODE_VERSION: 10.2 + IOS_PLATFORM_VERSION: 12.2 + IOS_DEVICE_NAME: iPhone X steps: - task: NodeTool@0 inputs: - versionSpec: '8.x' + versionSpec: '11.x' - script: | echo "Configuring Environment" - echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;$(ANDROID_EMU_TARGET);google_apis;$(ANDROID_EMU_ABI)' - echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n "$(ANDROID_EMU_NAME)" -k 'system-images;$(ANDROID_EMU_TARGET);google_apis;$(ANDROID_EMU_ABI)' --force + echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;$(ANDROID_EMU_TARGET);$(ANDROID_EMU_TAG);$(ANDROID_EMU_ABI)' + echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n "$(ANDROID_EMU_NAME)" -k 'system-images;$(ANDROID_EMU_TARGET);$(ANDROID_EMU_TAG);$(ANDROID_EMU_ABI)' --force echo $ANDROID_HOME/emulator/emulator -list-avds echo "Starting emulator" @@ -29,14 +33,17 @@ steps: $ANDROID_HOME/platform-tools/adb devices echo "Emulator started" + sudo xcode-select -s /Applications/Xcode_$(XCODE_VERSION).app/Contents/Developer + xcrun simctl list + npm config delete prefix - npm config set prefix $NVM_DIR/versions/node/v8.12.0 + npm config set prefix $NVM_DIR/versions/node/`node --version` + node --version + npm install -g appium@beta appium --version - node --version + java -version - which node - npm root -g - task: Gradle@2 inputs: @@ -47,4 +54,4 @@ steps: jdkArchitectureOption: 'x64' publishJUnitResults: true tasks: 'build' - options: 'xcuiTest uiAutomationTest -x test -x signArchives' + options: 'xcuiTest uiAutomationTest -x checkstyleTest -x test -x signArchives' diff --git a/google-style.xml b/google-style.xml index 33bdcef8a..2fb4cc988 100755 --- a/google-style.xml +++ b/google-style.xml @@ -159,11 +159,6 @@ - - - - - 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 bf93da2df..ac2850595 100644 --- a/src/test/java/io/appium/java_client/android/SettingTest.java +++ b/src/test/java/io/appium/java_client/android/SettingTest.java @@ -1,12 +1,12 @@ package io.appium.java_client.android; -import static org.junit.Assert.assertEquals; - import io.appium.java_client.Setting; import org.junit.Test; import java.time.Duration; +import static org.junit.Assert.assertEquals; + public class SettingTest extends BaseAndroidTest { @Test public void ignoreUnimportantViewsTest() { diff --git a/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java index a1774ef58..f6d8db2bd 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java @@ -3,18 +3,19 @@ import static org.junit.Assert.assertEquals; import io.appium.java_client.AppiumDriver; -import io.appium.java_client.service.local.AppiumServiceBuilder; +import io.appium.java_client.service.local.AppiumDriverLocalService; import org.junit.After; import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.DesiredCapabilities; import java.util.function.BiPredicate; import java.util.function.Supplier; public class BaseElementGenerationTest { protected AppiumDriver driver; + private AppiumDriverLocalService service; + protected final BiPredicate> commonPredicate = (by, aClass) -> { WebElement element = driver.findElement(by); assertEquals(element.getClass(), aClass); @@ -23,19 +24,24 @@ public class BaseElementGenerationTest { @After public void tearDown() { - if (driver != null) { - driver.quit(); + try { + if (driver != null) { + driver.quit(); + } + if (service != null) { + service.stop(); + } + } finally { + driver = null; + service = null; } - driver = null; } - protected boolean check(Supplier serverCapabilitiesSupplier, - Supplier clientCapabilitiesSupplier, + protected boolean check(Supplier capabilitiesSupplier, BiPredicate> filter, By by, Class clazz) { - AppiumServiceBuilder builder = new AppiumServiceBuilder() - .withCapabilities(serverCapabilitiesSupplier.get()); - driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get()); + service = AppiumDriverLocalService.buildDefaultService(); + driver = new AppiumDriver<>(service, capabilitiesSupplier.get()); return filter.test(by, clazz); } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java index 1e8223af3..992cb43cf 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java @@ -21,7 +21,7 @@ public class AndroidElementGeneratingTest extends BaseElementGenerationTest { private final File app = new File(new File("src/test/java/io/appium/java_client"), "ApiDemos-debug.apk"); - private final Supplier serverCapabilitiesSupplier = () -> { + private final Supplier commonCapabilitiesSupplier = () -> { DesiredCapabilities serverCapabilities = new DesiredCapabilities(); serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); @@ -29,42 +29,42 @@ public class AndroidElementGeneratingTest extends BaseElementGenerationTest { return serverCapabilities; }; - @Test public void whenAndroidNativeAppIsLaunched() { - assertTrue(check(serverCapabilitiesSupplier, () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + @Test + public void whenAndroidNativeAppIsLaunched() { + assertTrue(check(() -> { + DesiredCapabilities clientCapabilities = commonCapabilitiesSupplier.get(); clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); return clientCapabilities; }, commonPredicate, AndroidUIAutomator("new UiSelector().clickable(true)"), - AndroidElement.class)); + AndroidElement.class)); } - @Test public void whenAndroidHybridAppIsLaunched() { - assertTrue(check(serverCapabilitiesSupplier, () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + @Test + public void whenAndroidHybridAppIsLaunched() { + assertTrue(check(() -> { + DesiredCapabilities clientCapabilities = commonCapabilitiesSupplier.get(); clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); return clientCapabilities; }, (by, aClass) -> { - driver.context("WEBVIEW_io.appium.android.apis"); - return commonPredicate.test(by, aClass); - }, tagName("a"), AndroidElement.class)); + driver.context("WEBVIEW_io.appium.android.apis"); + return commonPredicate.test(by, aClass); + }, tagName("a"), AndroidElement.class)); } - @Test public void whenAndroidBrowserIsLaunched() { + @Test + public void whenAndroidBrowserIsLaunched() { assertTrue(check(() -> { - DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); - serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); - return serverCapabilities; - }, () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - return clientCapabilities; - }, (by, aClass) -> { - driver.get("https://www.google.com"); - return commonPredicate.test(by, aClass); - }, name("q"), AndroidElement.class)); + DesiredCapabilities clientCapabilities = commonCapabilitiesSupplier.get(); + clientCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); + clientCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); + clientCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + return clientCapabilities; + }, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, name("q"), AndroidElement.class)); } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java index 049661e0e..0b7572be3 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -7,6 +7,7 @@ import static org.openqa.selenium.By.partialLinkText; import io.appium.java_client.appium.element.generation.BaseElementGenerationTest; +import io.appium.java_client.ios.BaseIOSTest; import io.appium.java_client.ios.IOSElement; import io.appium.java_client.remote.IOSMobileCapabilityType; import io.appium.java_client.remote.MobileBrowserType; @@ -31,18 +32,13 @@ public class IOSElementGenerationTest extends BaseElementGenerationTest { private static final File webViewApp = new File(new File("src/test/java/io/appium/java_client"), "vodqa.zip"); - private static final String PLATFORM_VERSION = System.getenv("platformVersion") != null - ? System.getenv("platformVersion") : "11.4"; - private static final String DEVICE_NAME = System.getenv("deviceName") != null - ? System.getenv("deviceName") : "iPhone X"; - - private Supplier serverAppCapabilitiesSupplier = () -> { + private Supplier commonAppCapabilitiesSupplier = () -> { DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME); + serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, BaseIOSTest.DEVICE_NAME); serverCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); //some environment is too slow - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, BaseIOSTest.PLATFORM_VERSION); serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); return serverCapabilities; }; @@ -58,8 +54,8 @@ public class IOSElementGenerationTest extends BaseElementGenerationTest { private final Supplier serverBrowserCapabilitiesSupplier = () -> { DesiredCapabilities serverCapabilities = new DesiredCapabilities(); serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); - serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, BaseIOSTest.PLATFORM_VERSION); + serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, BaseIOSTest.DEVICE_NAME); //sometimes environment has performance problems serverCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); return serverCapabilities; @@ -73,66 +69,73 @@ public class IOSElementGenerationTest extends BaseElementGenerationTest { @Test public void whenIOSNativeAppIsLaunched() { - assertTrue(check(serverAppCapabilitiesSupplier, - appFileSupplierFunction.apply(testApp), - commonPredicate, - AccessibilityId("Answer"), - IOSElement.class)); + assertTrue(check(() -> { + Capabilities caps = commonAppCapabilitiesSupplier.get(); + return caps.merge(appFileSupplierFunction.apply(testApp).get()); + }, commonPredicate, + AccessibilityId("Answer"), + IOSElement.class)); } @Ignore - @Test public void whenIOSHybridAppIsLaunched() { - assertTrue(check(serverAppCapabilitiesSupplier, - appFileSupplierFunction.apply(webViewApp), - (by, aClass) -> { - new WebDriverWait(driver, 30) - .until(ExpectedConditions.presenceOfElementLocated(id("login"))) - .click(); - driver.findElementByAccessibilityId("webView").click(); - new WebDriverWait(driver, 30) - .until(ExpectedConditions - .presenceOfElementLocated(AccessibilityId("Webview"))); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); + @Test + public void whenIOSHybridAppIsLaunched() { + assertTrue(check(() -> { + Capabilities caps = commonAppCapabilitiesSupplier.get(); + return caps.merge(appFileSupplierFunction.apply(webViewApp).get()); + }, (by, aClass) -> { + new WebDriverWait(driver, 30) + .until(ExpectedConditions.presenceOfElementLocated(id("login"))) + .click(); + driver.findElementByAccessibilityId("webView").click(); + new WebDriverWait(driver, 30) + .until(ExpectedConditions + .presenceOfElementLocated(AccessibilityId("Webview"))); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + driver.getContextHandles().forEach((handle) -> { + if (handle.contains("WEBVIEW")) { + driver.context(handle); } - driver.getContextHandles().forEach((handle) -> { - if (handle.contains("WEBVIEW")) { - driver.context(handle); - } - }); - return commonPredicate.test(by, aClass); - }, partialLinkText("login"), IOSElement.class)); + }); + return commonPredicate.test(by, aClass); + }, partialLinkText("login"), IOSElement.class)); } - @Test public void whenIOSBrowserIsLaunched() { - assertTrue(check(serverBrowserCapabilitiesSupplier, - clientBrowserCapabilitiesSupplier, (by, aClass) -> { - driver.get("https://www.google.com"); - return commonPredicate.test(by, aClass); - }, name("q"), IOSElement.class)); + @Test + public void whenIOSBrowserIsLaunched() { + assertTrue(check(() -> { + Capabilities caps = serverBrowserCapabilitiesSupplier.get(); + return caps.merge(clientBrowserCapabilitiesSupplier.get()); + }, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, name("q"), IOSElement.class)); } @Test public void whenIOSNativeAppIsLaunched2() { assertTrue(check(() -> { - DesiredCapabilities serverCapabilities = serverAppCapabilitiesSupplier.get(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); + DesiredCapabilities serverCapabilities = commonAppCapabilitiesSupplier.get(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, BaseIOSTest.PLATFORM_VERSION); serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); - return serverCapabilities; - }, appFileSupplierFunction.apply(testApp), commonPredicate, id("IntegerA"), IOSElement.class)); + return serverCapabilities.merge(appFileSupplierFunction.apply(testApp).get()); + }, commonPredicate, id("IntegerA"), IOSElement.class)); } - @Test public void whenIOSBrowserIsLaunched2() { + @Test + public void whenIOSBrowserIsLaunched2() { assertTrue(check(() -> { DesiredCapabilities serverCapabilities = serverBrowserCapabilitiesSupplier.get(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, BaseIOSTest.PLATFORM_VERSION); serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); - return serverCapabilities; - }, clientBrowserCapabilitiesSupplier, (by, aClass) -> { - driver.get("https://www.google.com"); - return commonPredicate.test(by, aClass); - }, name("q"), IOSElement.class)); + return serverCapabilities.merge(clientBrowserCapabilitiesSupplier.get()); + }, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, name("q"), IOSElement.class)); } } diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java index 2777ce1c4..695a9cb5d 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java @@ -16,7 +16,6 @@ package io.appium.java_client.ios; -import io.appium.java_client.remote.MobileBrowserType; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; import org.junit.AfterClass; @@ -29,12 +28,10 @@ public class BaseIOSTest { protected static AppiumDriverLocalService service; protected static IOSDriver driver; protected static final int PORT = 4723; - protected static final String DEVICE_NAME = System.getenv("deviceName") != null - ? System.getenv("deviceName") : "iPhone X"; - protected static final String PLATFORM_VERSION = System.getenv("platformVersion") != null - ? System.getenv("platformVersion") : "11.4"; - protected static final String BROWSER_NAME = System.getenv("browserName") != null - ? System.getenv("browserName") : MobileBrowserType.SAFARI; + public static final String DEVICE_NAME = System.getenv("IOS_DEVICE_NAME") != null + ? System.getenv("IOS_DEVICE_NAME") : "iPhone X"; + public static final String PLATFORM_VERSION = System.getenv("IOS_PLATFORM_VERSION") != null + ? System.getenv("IOS_PLATFORM_VERSION") : "11.4"; /** 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 fc72ee11b..a47adb19d 100644 --- a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseSafariTest.java @@ -18,6 +18,7 @@ import io.appium.java_client.remote.AutomationName; import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileBrowserType; import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.BeforeClass; @@ -37,7 +38,7 @@ public class BaseSafariTest extends BaseIOSTest { } DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, BROWSER_NAME); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI); capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST); capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); //sometimes environment has performance problems diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/test/java/io/appium/java_client/ios/IOSElementTest.java index 98b294777..4389d1888 100644 --- a/src/test/java/io/appium/java_client/ios/IOSElementTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSElementTest.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertThat; import org.junit.FixMethodOrder; +import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; import org.openqa.selenium.By; @@ -14,15 +15,20 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class IOSElementTest extends AppIOSTest { - @Test public void findByAccessibilityIdTest() { + @Test + public void findByAccessibilityIdTest() { assertThat(driver.findElementsByAccessibilityId("Compute Sum").size(), not(is(0))); } - @Test public void setValueTest() { + // FIXME: Stabilize the test on CI + @Ignore + @Test + public void setValueTest() { WebDriverWait wait = new WebDriverWait(driver, 20); - IOSElement slider = wait.until(driver1 -> driver1.findElement(By.className("XCUIElementTypeSlider"))); + IOSElement slider = wait.until( + driver1 -> driver1.findElement(By.className("XCUIElementTypeSlider"))); slider.setValue("0%"); assertEquals("0%", slider.getAttribute("value")); } diff --git a/src/test/java/io/appium/java_client/ios/SettingTest.java b/src/test/java/io/appium/java_client/ios/SettingTest.java index a93f1ff1c..16fd358df 100644 --- a/src/test/java/io/appium/java_client/ios/SettingTest.java +++ b/src/test/java/io/appium/java_client/ios/SettingTest.java @@ -17,11 +17,12 @@ package io.appium.java_client.ios; -import static org.junit.Assert.assertEquals; - import io.appium.java_client.Setting; import org.junit.Test; +import static org.junit.Assert.assertEquals; + + public class SettingTest extends AppIOSTest { @Test public void testSetShouldUseCompactResponses() { diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java index 618fac97e..ab7c1d912 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java +++ b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue; import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.ios.BaseIOSTest; import io.appium.java_client.ios.IOSDriver; import io.appium.java_client.remote.AndroidMobileCapabilityType; import io.appium.java_client.remote.AutomationName; @@ -39,12 +40,6 @@ public class StartingAppLocallyTest { - private static final String PLATFORM_VERSION = System.getenv("platformVersion") != null - ? System.getenv("platformVersion") : "11.4"; - - private static final String DEVICE_NAME = System.getenv("deviceName") != null - ? System.getenv("deviceName") : "iPhone X"; - @Test public void startingAndroidAppWithCapabilitiesOnlyTest() { File appDir = new File("src/test/java/io/appium/java_client"); File app = new File(appDir, "ApiDemos-debug.apk"); @@ -130,10 +125,10 @@ public class StartingAppLocallyTest { File app = new File(appDir, "UICatalog.app.zip"); DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, BaseIOSTest.PLATFORM_VERSION); //sometimes environment has performance problems capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, BaseIOSTest.DEVICE_NAME); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM); @@ -144,7 +139,7 @@ public class StartingAppLocallyTest { assertEquals(AutomationName.APPIUM, caps.getCapability(MobileCapabilityType.AUTOMATION_NAME)); assertEquals(MobilePlatform.IOS, caps.getCapability(MobileCapabilityType.PLATFORM_NAME)); assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME)); - assertEquals(PLATFORM_VERSION, caps.getCapability(MobileCapabilityType.PLATFORM_VERSION)); + assertEquals(BaseIOSTest.PLATFORM_VERSION, caps.getCapability(MobileCapabilityType.PLATFORM_VERSION)); assertEquals(app.getAbsolutePath(), caps.getCapability(MobileCapabilityType.APP)); } finally { driver.quit(); @@ -157,10 +152,10 @@ public class StartingAppLocallyTest { File app = new File(appDir, "UICatalog.app.zip"); DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, BaseIOSTest.DEVICE_NAME); capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, BaseIOSTest.PLATFORM_VERSION); //sometimes environment has performance problems capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); @@ -181,10 +176,10 @@ public class StartingAppLocallyTest { @Test public void startingIOSAppWithCapabilitiesAndFlagsOnServerSideTest() { DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME); + serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, BaseIOSTest.DEVICE_NAME); serverCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); //some environment is too slow - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, BaseIOSTest.PLATFORM_VERSION); serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); File appDir = new File("src/test/java/io/appium/java_client"); From 924f544acf966c8c02fa68b23118820c04066fb6 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 18 Jun 2019 00:46:42 +0200 Subject: [PATCH 005/675] Bump dependencies (#1158) * Bump dependencies * Put gradle wrapper back --- build.gradle | 14 +++++++------- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 18 +++++++++++++++++- gradlew.bat | 18 +++++++++++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index de9c1984f..000a771e9 100644 --- a/build.gradle +++ b/build.gradle @@ -67,18 +67,18 @@ dependencies { force = true } compile 'com.google.code.gson:gson:2.8.5' - compile 'org.apache.httpcomponents:httpclient:4.5.7' + compile 'org.apache.httpcomponents:httpclient:4.5.8' compile 'cglib:cglib:3.2.10' compile 'commons-validator:commons-validator:1.6' - compile 'org.apache.commons:commons-lang3:3.8.1' + compile 'org.apache.commons:commons-lang3:3.9' compile 'commons-io:commons-io:2.6' - compile 'org.springframework:spring-context:5.1.4.RELEASE' - compile 'org.aspectj:aspectjweaver:1.9.2' - compile 'org.slf4j:slf4j-api:1.7.25' + compile 'org.springframework:spring-context:5.1.6.RELEASE' + compile 'org.aspectj:aspectjweaver:1.9.3' + compile 'org.slf4j:slf4j-api:1.7.26' testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest:2.1' - testCompile (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.2.0') { + testCompile (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.4.0') { exclude group: 'org.seleniumhq.selenium' } } @@ -195,7 +195,7 @@ uploadArchives { } wrapper { - gradleVersion = '5.0' + gradleVersion = '5.4' distributionType = Wrapper.DistributionType.ALL } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ee671127f..ed5aaee4f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d51..b0d6d0ab5 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# 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. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/gradlew.bat b/gradlew.bat index e95643d6a..15e1ee37a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome From 6d0de818812878009e15fc055136933b14030020 Mon Sep 17 00:00:00 2001 From: Valery Yatsynovich Date: Tue, 18 Jun 2019 08:42:25 +0300 Subject: [PATCH 006/675] Upgrade to Selenium 4.0.0-alpha-1 (#1132) --- gradle.properties | 2 +- .../io/appium/java_client/remote/AppiumCommandExecutor.java | 2 +- .../io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9bd535700..5a9863788 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ signing.secretKeyRingFile=PathToYourKeyRingFile ossrhUsername=your-jira-id ossrhPassword=your-jira-password -selenium.version=3.141.59 +selenium.version=4.0.0-alpha-1 diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index 3f094ff53..707680b4f 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -44,10 +44,10 @@ import org.openqa.selenium.remote.ProtocolHandshake; import org.openqa.selenium.remote.Response; import org.openqa.selenium.remote.ResponseCodec; +import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; import org.openqa.selenium.remote.http.HttpClient; import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; -import org.openqa.selenium.remote.http.W3CHttpCommandCodec; import org.openqa.selenium.remote.service.DriverService; import java.io.BufferedInputStream; diff --git a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java index aec7ebd75..0fe0ace05 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java +++ b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java @@ -32,7 +32,7 @@ import org.openqa.selenium.interactions.KeyInput; import org.openqa.selenium.interactions.Sequence; -import org.openqa.selenium.remote.http.W3CHttpCommandCodec; +import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; import java.util.Collection; import java.util.Map; From 3249bd61b0043035a0734d935dbe88b7c71e89c0 Mon Sep 17 00:00:00 2001 From: Anil Verma Date: Fri, 21 Jun 2019 18:32:00 +0530 Subject: [PATCH 007/675] Implemented driver status check. (#1153) * - Implemented driver status check. - Solves Issue: #1137 * - Made version field private. * - Changed the getStatus() method implementation to return versionMap instead of AppiumServerStatus class object. - Deleted AppiumServerStatus class as it is no longer needed. * Fixed below checkstyle violations: - Empty line should be followed by

tag on the next line. 234 - First sentence of Javadoc is missing an ending period. 234 Ran ./gradlew clean checkstyleMain, BUILD is SUCCESSFUL now. * - Updated getStatus() method to return statusMap. * - Made return statement inline. --- .../io/appium/java_client/AppiumDriver.java | 100 +++++++++------ .../android/AndroidDriverTest.java | 121 ++++++++++++------ 2 files changed, 141 insertions(+), 80 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 854d76239..eab19e283 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -56,15 +56,15 @@ * Default Appium driver implementation. * * @param the required type of class which implement {@link WebElement}. - * Instances of the defined type will be returned via findElement* and findElements* - * Warning (!!!). Allowed types: - * {@link WebElement}, {@link org.openqa.selenium.remote.RemoteWebElement}, - * {@link MobileElement} and its subclasses that designed - * specifically for each target mobile OS (still Android and iOS) -*/ + * Instances of the defined type will be returned via findElement* and findElements* + * Warning (!!!). Allowed types: + * {@link WebElement}, {@link org.openqa.selenium.remote.RemoteWebElement}, + * {@link MobileElement} and its subclasses that designed + * specifically for each target mobile OS (still Android and iOS) + */ @SuppressWarnings("unchecked") public class AppiumDriver - extends DefaultGenericMobileDriver implements ComparesImages, FindsByImage, FindsByCustom { + extends DefaultGenericMobileDriver implements ComparesImages, FindsByImage, FindsByCustom { private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true); // frequently used command parameters @@ -75,9 +75,9 @@ public class AppiumDriver /** * Creates a new instance based on command {@code executor} and {@code capabilities}. * - * @param executor is an instance of {@link HttpCommandExecutor} - * or class that extends it. Default commands or another vendor-specific - * commands may be specified there. + * @param executor is an instance of {@link HttpCommandExecutor} + * or class that extends it. Default commands or another vendor-specific + * commands may be specified there. * @param capabilities take a look at {@link Capabilities} */ public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) { @@ -91,24 +91,24 @@ public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) { public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress), - desiredCapabilities); + desiredCapabilities); } public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, - Capabilities desiredCapabilities) { + Capabilities desiredCapabilities) { this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress, - httpClientFactory), desiredCapabilities); + httpClientFactory), desiredCapabilities); } public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) { this(new AppiumCommandExecutor(MobileCommand.commandRepository, service), - desiredCapabilities); + desiredCapabilities); } public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, - Capabilities desiredCapabilities) { + Capabilities desiredCapabilities) { this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory), - desiredCapabilities); + desiredCapabilities); } public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) { @@ -116,13 +116,13 @@ public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabiliti } public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, - Capabilities desiredCapabilities) { + Capabilities desiredCapabilities) { this(builder.build(), httpClientFactory, desiredCapabilities); } public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory, - desiredCapabilities); + desiredCapabilities); } public AppiumDriver(Capabilities desiredCapabilities) { @@ -133,26 +133,29 @@ public AppiumDriver(Capabilities desiredCapabilities) { * Changes platform name and returns new capabilities. * * @param originalCapabilities the given {@link Capabilities}. - * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has - * to be set up + * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has + * to be set up * @return {@link Capabilities} with changed mobile platform value */ protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities, - String newPlatform) { + String newPlatform) { DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); dc.setCapability(PLATFORM_NAME, newPlatform); return dc; } - @Override public List findElements(By by) { + @Override + public List findElements(By by) { return super.findElements(by); } - @Override public List findElements(String by, String using) { + @Override + public List findElements(String by, String using) { return super.findElements(by, using); } - @Override public List findElementsById(String id) { + @Override + public List findElementsById(String id) { return super.findElementsById(id); } @@ -184,15 +187,18 @@ public List findElementsByXPath(String using) { return super.findElementsByXPath(using); } - @Override public List findElementsByAccessibilityId(String using) { + @Override + public List findElementsByAccessibilityId(String using) { return super.findElementsByAccessibilityId(using); } - @Override public ExecuteMethod getExecuteMethod() { + @Override + public ExecuteMethod getExecuteMethod() { return executeMethod; } - @Override public WebDriver context(String name) { + @Override + public WebDriver context(String name) { checkNotNull(name, "Must supply a context name"); try { execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name)); @@ -202,7 +208,8 @@ public List findElementsByXPath(String using) { } } - @Override public Set getContextHandles() { + @Override + public Set getContextHandles() { Response response = execute(DriverCommand.GET_CONTEXT_HANDLES); Object value = response.getValue(); try { @@ -210,20 +217,31 @@ public List findElementsByXPath(String using) { return new LinkedHashSet<>(returnedValues); } catch (ClassCastException ex) { throw new WebDriverException( - "Returned value cannot be converted to List: " + value, ex); + "Returned value cannot be converted to List: " + value, ex); } } - @Override public String getContext() { + @Override + public String getContext() { String contextName = - String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue()); + String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue()); if ("null".equalsIgnoreCase(contextName)) { return null; } return contextName; } - @Override public DeviceRotation rotation() { + /** + * This method is used to get build version status of running Appium server. + * + * @return map containing version details + */ + public Map getStatus() { + return (Map) execute(DriverCommand.STATUS).getValue(); + } + + @Override + public DeviceRotation rotation() { Response response = execute(DriverCommand.GET_SCREEN_ROTATION); DeviceRotation deviceRotation = new DeviceRotation((Map) response.getValue()); @@ -233,17 +251,20 @@ public List findElementsByXPath(String using) { return deviceRotation; } - @Override public void rotate(DeviceRotation rotation) { + @Override + public void rotate(DeviceRotation rotation) { execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters()); } - @Override public void rotate(ScreenOrientation orientation) { + @Override + public void rotate(ScreenOrientation orientation) { execute(DriverCommand.SET_SCREEN_ORIENTATION, ImmutableMap.of("orientation", orientation.value().toUpperCase())); } - @Override public ScreenOrientation getOrientation() { + @Override + public ScreenOrientation getOrientation() { Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION); String orientation = response.getValue().toString().toLowerCase(); if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) { @@ -255,11 +276,13 @@ public List findElementsByXPath(String using) { } } - @Override public Location location() { + @Override + public Location location() { return locationContext.location(); } - @Override public void setLocation(Location location) { + @Override + public void setLocation(Location location) { locationContext.setLocation(location); } @@ -267,7 +290,8 @@ public URL getRemoteAddress() { return remoteAddress; } - @Override public boolean isBrowser() { + @Override + public boolean isBrowser() { return super.isBrowser() && !containsIgnoreCase(getContext(), "NATIVE_APP"); } diff --git a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java index f2dedab97..f4b41348a 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -29,6 +29,7 @@ import io.appium.java_client.appmanagement.ApplicationState; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; +import org.hamcrest.Matchers; import org.junit.Test; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.html5.Location; @@ -42,7 +43,8 @@ public class AndroidDriverTest extends BaseAndroidTest { - @Test public void sendSMSTest() { + @Test + public void sendSMSTest() { try { driver.sendSMS("11111111", "call"); } catch (Exception e) { @@ -50,7 +52,14 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void gsmCallTest() { + + @Test + public void getStatusTest() { + assertThat(driver.getStatus().get("build").toString(), Matchers.containsString(".")); + } + + @Test + public void gsmCallTest() { try { driver.makeGsmCall("11111111", GsmCallActions.CALL); driver.makeGsmCall("11111111", GsmCallActions.ACCEPT); @@ -59,7 +68,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void toggleWiFi() { + @Test + public void toggleWiFi() { try { driver.toggleWifi(); } catch (Exception e) { @@ -67,7 +77,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void toggleAirplane() { + @Test + public void toggleAirplane() { try { driver.toggleAirplaneMode(); } catch (Exception e) { @@ -75,7 +86,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void toggleData() { + @Test + public void toggleData() { try { driver.toggleData(); } catch (Exception e) { @@ -83,7 +95,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void gsmSignalStrengthTest() { + @Test + public void gsmSignalStrengthTest() { try { driver.setGsmSignalStrength(GsmSignalStrength.GREAT); } catch (Exception e) { @@ -91,7 +104,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void gsmVoiceTest() { + @Test + public void gsmVoiceTest() { try { driver.setGsmVoice(GsmVoiceState.OFF); } catch (Exception e) { @@ -99,7 +113,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void networkSpeedTest() { + @Test + public void networkSpeedTest() { try { driver.setNetworkSpeed(NetworkSpeed.EDGE); } catch (Exception e) { @@ -107,7 +122,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void powerTest() { + @Test + public void powerTest() { try { driver.setPowerCapacity(100); driver.setPowerAC(PowerACState.OFF); @@ -116,71 +132,81 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void getDeviceTimeTest() { + @Test + public void getDeviceTimeTest() { String time = driver.getDeviceTime(); assertFalse(time.isEmpty()); } - @Test public void isAppInstalledTest() { + @Test + public void isAppInstalledTest() { assertTrue(driver.isAppInstalled("com.example.android.apis")); } - @Test public void isAppNotInstalledTest() { + @Test + public void isAppNotInstalledTest() { assertFalse(driver.isAppInstalled("foo")); } - @Test public void closeAppTest() { + @Test + public void closeAppTest() { driver.closeApp(); driver.launchApp(); assertEquals(".ApiDemos", driver.currentActivity()); } - @Test public void pushFileTest() { + @Test + public void pushFileTest() { byte[] data = Base64.encodeBase64( - "The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra" - .getBytes()); + "The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra" + .getBytes()); driver.pushFile("/data/local/tmp/remote.txt", data); byte[] returnData = driver.pullFile("/data/local/tmp/remote.txt"); String returnDataDecoded = new String(returnData); assertEquals( - "The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra", - returnDataDecoded); + "The eventual code is no more than the deposit of your understanding. ~E. W. Dijkstra", + returnDataDecoded); } - @Test public void pushTempFileTest() throws Exception { + @Test + public void pushTempFileTest() throws Exception { File temp = File.createTempFile("Temp_", "_test"); try { FileUtils.writeStringToFile(temp, "The eventual code is no " - + "more than the deposit of your understanding. ~E. W. Dijkstra", "UTF-8", true); + + "more than the deposit of your understanding. ~E. W. Dijkstra", "UTF-8", true); driver.pushFile("/data/local/tmp/remote2.txt", temp); byte[] returnData = driver.pullFile("/data/local/tmp/remote2.txt"); String returnDataDecoded = new String(returnData); assertEquals( - "The eventual code is no more than the deposit of " - + "your understanding. ~E. W. Dijkstra", - returnDataDecoded); + "The eventual code is no more than the deposit of " + + "your understanding. ~E. W. Dijkstra", + returnDataDecoded); } finally { FileUtils.forceDelete(temp); } } - @Test public void toggleLocationServicesTest() { + @Test + public void toggleLocationServicesTest() { driver.toggleLocationServices(); } - @Test public void geolocationTest() { + @Test + public void geolocationTest() { Location location = new Location(45, 45, 100); driver.setLocation(location); } - @Test public void orientationTest() { + @Test + public void orientationTest() { assertEquals(ScreenOrientation.PORTRAIT, driver.getOrientation()); driver.rotate(ScreenOrientation.LANDSCAPE); assertEquals(ScreenOrientation.LANDSCAPE, driver.getOrientation()); driver.rotate(ScreenOrientation.PORTRAIT); } - @Test public void lockTest() { + @Test + public void lockTest() { try { driver.lockDevice(); assertTrue(driver.isDeviceLocked()); @@ -190,14 +216,16 @@ public class AndroidDriverTest extends BaseAndroidTest { } } - @Test public void runAppInBackgroundTest() { + @Test + public void runAppInBackgroundTest() { long time = System.currentTimeMillis(); driver.runAppInBackground(Duration.ofSeconds(4)); long timeAfter = System.currentTimeMillis(); assert (timeAfter - time > 3000); } - @Test public void testApplicationsManagement() throws InterruptedException { + @Test + public void testApplicationsManagement() throws InterruptedException { String appId = driver.getCurrentPackage(); assertThat(driver.queryAppState(appId), equalTo(ApplicationState.RUNNING_IN_FOREGROUND)); Thread.sleep(500); @@ -208,37 +236,44 @@ public class AndroidDriverTest extends BaseAndroidTest { assertThat(driver.queryAppState(appId), equalTo(ApplicationState.RUNNING_IN_FOREGROUND)); } - @Test public void pullFileTest() { + @Test + public void pullFileTest() { byte[] data = - driver.pullFile("/data/system/users/userlist.xml"); + driver.pullFile("/data/system/users/userlist.xml"); assert (data.length > 0); } - @Test public void resetTest() { + @Test + public void resetTest() { driver.resetApp(); } - @Test public void endTestCoverage() { + @Test + public void endTestCoverage() { driver.endTestCoverage("android.intent.action.MAIN", ""); } - @Test public void getDeviceUDIDTest() { + @Test + public void getDeviceUDIDTest() { String deviceSerial = driver.getSessionDetail("deviceUDID").toString(); assertNotNull(deviceSerial); } - @Test public void getSessionMapData() { - Map map = (Map) driver.getSessionDetail("desired"); + @Test + public void getSessionMapData() { + Map map = (Map) driver.getSessionDetail("desired"); assertNotEquals(map.size(), 0); } - - @Test public void deviceDetailsAndKeyboardTest() { + + @Test + public void deviceDetailsAndKeyboardTest() { assertFalse(driver.isKeyboardShown()); assertNotNull(driver.getDisplayDensity()); assertNotEquals(0, driver.getSystemBars().size()); } - @Test public void getSupportedPerformanceDataTypesTest() { + @Test + public void getSupportedPerformanceDataTypesTest() { driver.startActivity(new Activity(APP_ID, ".ApiDemos")); List dataTypes = new ArrayList<>(); @@ -251,14 +286,15 @@ public class AndroidDriverTest extends BaseAndroidTest { assertEquals(4, supportedPerformanceDataTypes.size()); - for ( int i = 0 ; i < supportedPerformanceDataTypes.size() ; ++i) { + for (int i = 0; i < supportedPerformanceDataTypes.size(); ++i) { assertEquals(dataTypes.get(i), supportedPerformanceDataTypes.get(i)); } } - @Test public void getPerformanceDataTest() { + @Test + public void getPerformanceDataTest() { driver.startActivity(new Activity(APP_ID, ".ApiDemos")); List supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes(); @@ -274,7 +310,8 @@ public class AndroidDriverTest extends BaseAndroidTest { } - @Test public void getCurrentPackageTest() { + @Test + public void getCurrentPackageTest() { assertEquals(APP_ID, driver.getCurrentPackage()); } From 50744b39372471ec833fddc4a3f6b1b987ef1e42 Mon Sep 17 00:00:00 2001 From: Takeshi Kishi Date: Sat, 22 Jun 2019 21:12:19 +0900 Subject: [PATCH 008/675] fix broken android tests (#1161) --- .../java/io/appium/java_client/android/AndroidDriverTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java index f4b41348a..65d086ad5 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -140,7 +140,7 @@ public void getDeviceTimeTest() { @Test public void isAppInstalledTest() { - assertTrue(driver.isAppInstalled("com.example.android.apis")); + assertTrue(driver.isAppInstalled(APP_ID)); } @Test @@ -301,7 +301,7 @@ public void getPerformanceDataTest() { for (String dataType : supportedPerformanceDataTypes) { - List> valueTable = driver.getPerformanceData("com.example.android.apis", dataType, 60000); + List> valueTable = driver.getPerformanceData(APP_ID, dataType, 60000); for (int j = 1; j < valueTable.size(); ++j) { assertEquals(valueTable.subList(0, 0).size(), valueTable.subList(j, j).size()); From ef719245954855a3ed098e0584fad15453ec6693 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 25 Jun 2019 08:58:15 +0200 Subject: [PATCH 009/675] Avoid enforcing the platform name while creating drivers (#1164) --- .../io/appium/java_client/AppiumDriver.java | 34 ++++++++++++++++ .../java_client/android/AndroidDriver.java | 35 +++++------------ .../io/appium/java_client/ios/IOSDriver.java | 39 +++++-------------- .../java_client/windows/WindowsDriver.java | 18 ++++----- 4 files changed, 62 insertions(+), 64 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index eab19e283..4fc4c49ee 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -31,6 +31,7 @@ import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; import org.openqa.selenium.DeviceRotation; +import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; @@ -136,7 +137,9 @@ public AppiumDriver(Capabilities desiredCapabilities) { * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has * to be set up * @return {@link Capabilities} with changed mobile platform value + * @deprecated Please use {@link #updateDefaultPlatformName(Capabilities, String)} instead */ + @Deprecated protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities, String newPlatform) { DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); @@ -144,6 +147,24 @@ protected static Capabilities substituteMobilePlatform(Capabilities originalCapa return dc; } + /** + * Changes platform name if it is not set and returns new capabilities. + * + * @param originalCapabilities the given {@link Capabilities}. + * @param defaultName a {@link MobileCapabilityType#PLATFORM_NAME} value which has + * to be set up + * @return {@link Capabilities} with changed mobile platform name value or the original capabilities + */ + protected static Capabilities updateDefaultPlatformName(Capabilities originalCapabilities, + String defaultName) { + if (originalCapabilities.getCapability(PLATFORM_NAME) == null) { + DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); + dc.setCapability(PLATFORM_NAME, defaultName); + return dc; + } + return originalCapabilities; + } + @Override public List findElements(By by) { return super.findElements(by); @@ -295,4 +316,17 @@ public boolean isBrowser() { return super.isBrowser() && !containsIgnoreCase(getContext(), "NATIVE_APP"); } + + @Override + protected void startSession(Capabilities capabilities) { + super.startSession(capabilities); + // The RemoteWebDriver implementation overrides platformName + // so we need to restore it back to the original value + Object originalPlatformName = capabilities.getCapability(PLATFORM_NAME); + Capabilities originalCaps = super.getCapabilities(); + if (originalPlatformName != null && originalCaps instanceof MutableCapabilities) { + ((MutableCapabilities) super.getCapabilities()).setCapability(PLATFORM_NAME, + originalPlatformName); + } + } } 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 b1d9a454d..926363602 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -19,7 +19,6 @@ import static io.appium.java_client.android.AndroidMobileCommandHelper.endTestCoverageCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.openNotificationsCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand; -import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT; import com.google.common.collect.ImmutableMap; @@ -40,7 +39,6 @@ import io.appium.java_client.service.local.AppiumServiceBuilder; import io.appium.java_client.ws.StringWebSocketClient; import org.openqa.selenium.Capabilities; -import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.HttpCommandExecutor; import org.openqa.selenium.remote.http.HttpClient; @@ -48,7 +46,6 @@ import java.net.URL; import java.util.Collections; import java.util.Map; -import javax.annotation.Nullable; /** * Android driver implementation. @@ -84,7 +81,7 @@ public class AndroidDriver * @param capabilities take a look at {@link Capabilities} */ public AndroidDriver(HttpCommandExecutor executor, Capabilities capabilities) { - super(executor, substituteMobilePlatform(capabilities, ANDROID_PLATFORM)); + super(executor, updateDefaultPlatformName(capabilities, ANDROID_PLATFORM)); } /** @@ -94,7 +91,7 @@ public AndroidDriver(HttpCommandExecutor executor, Capabilities capabilities) { * @param desiredCapabilities take a look at {@link Capabilities} */ public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) { - super(remoteAddress, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + super(remoteAddress, updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -107,7 +104,7 @@ public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) { public AndroidDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(remoteAddress, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -117,7 +114,7 @@ public AndroidDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, * @param desiredCapabilities take a look at {@link Capabilities} */ public AndroidDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) { - super(service, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + super(service, updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -130,7 +127,7 @@ public AndroidDriver(AppiumDriverLocalService service, Capabilities desiredCapab public AndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(service, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -140,7 +137,7 @@ public AndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpCl * @param desiredCapabilities take a look at {@link Capabilities} */ public AndroidDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) { - super(builder, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + super(builder, updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -153,7 +150,7 @@ public AndroidDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilit public AndroidDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(builder, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -163,7 +160,7 @@ public AndroidDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClient * @param desiredCapabilities take a look at {@link Capabilities} */ public AndroidDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + super(httpClientFactory, updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -172,7 +169,7 @@ public AndroidDriver(HttpClient.Factory httpClientFactory, Capabilities desiredC * @param desiredCapabilities take a look at {@link Capabilities} */ public AndroidDriver(Capabilities desiredCapabilities) { - super(substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); + super(updateDefaultPlatformName(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -203,20 +200,6 @@ public AndroidBatteryInfo getBatteryInfo() { "script", "mobile: batteryInfo", "args", Collections.emptyList())).getValue()); } - /** - * Returns capabilities that were provided on instantiation. - * - * @return given {@link Capabilities} - */ - @Nullable - public Capabilities getCapabilities() { - MutableCapabilities capabilities = (MutableCapabilities) super.getCapabilities(); - if (capabilities != null) { - capabilities.setCapability(PLATFORM_NAME, ANDROID_PLATFORM); - } - return capabilities; - } - @Override public synchronized StringWebSocketClient getLogcatClient() { if (logcatClient == null) { 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 1cd2aa81b..1d668c5de 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -18,7 +18,6 @@ import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND; import static io.appium.java_client.MobileCommand.prepareArguments; -import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT; import com.google.common.collect.ImmutableMap; @@ -37,7 +36,6 @@ import io.appium.java_client.ws.StringWebSocketClient; import org.openqa.selenium.Alert; import org.openqa.selenium.Capabilities; -import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DriverCommand; import org.openqa.selenium.remote.HttpCommandExecutor; @@ -48,7 +46,6 @@ import java.time.Duration; import java.util.Collections; import java.util.Map; -import javax.annotation.Nullable; /** * iOS driver implementation. @@ -69,7 +66,7 @@ public class IOSDriver PushesFiles, CanRecordScreen, HasIOSClipboard, ListensToSyslogMessages, HasBattery { - private static final String IOS_PLATFORM = MobilePlatform.IOS; + private static final String IOS_DEFAULT_PLATFORM = MobilePlatform.IOS; private StringWebSocketClient syslogClient; @@ -82,7 +79,7 @@ public class IOSDriver * @param capabilities take a look at {@link Capabilities} */ public IOSDriver(HttpCommandExecutor executor, Capabilities capabilities) { - super(executor, substituteMobilePlatform(capabilities, IOS_PLATFORM)); + super(executor, updateDefaultPlatformName(capabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -92,7 +89,7 @@ public IOSDriver(HttpCommandExecutor executor, Capabilities capabilities) { * @param desiredCapabilities take a look at {@link Capabilities} */ public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) { - super(remoteAddress, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + super(remoteAddress, updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -105,7 +102,7 @@ public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) { public IOSDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(remoteAddress, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -115,7 +112,7 @@ public IOSDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, * @param desiredCapabilities take a look at {@link Capabilities} */ public IOSDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) { - super(service, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + super(service, updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -127,8 +124,7 @@ public IOSDriver(AppiumDriverLocalService service, Capabilities desiredCapabilit */ public IOSDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(service, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + super(service, httpClientFactory, updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -138,7 +134,7 @@ public IOSDriver(AppiumDriverLocalService service, HttpClient.Factory httpClient * @param desiredCapabilities take a look at {@link Capabilities} */ public IOSDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) { - super(builder, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + super(builder, updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -151,7 +147,7 @@ public IOSDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) public IOSDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(builder, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -161,7 +157,7 @@ public IOSDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFact * @param desiredCapabilities take a look at {@link Capabilities} */ public IOSDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + super(httpClientFactory, updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -170,7 +166,7 @@ public IOSDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapab * @param desiredCapabilities take a look at {@link Capabilities} */ public IOSDriver(Capabilities desiredCapabilities) { - super(substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); + super(updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } /** @@ -203,21 +199,6 @@ private class InnerTargetLocator extends RemoteTargetLocator { } } - /** - * Returns capabilities that were provided on instantiation. - * - * @return given {@link Capabilities} - */ - @Nullable - public Capabilities getCapabilities() { - MutableCapabilities capabilities = (MutableCapabilities) super.getCapabilities(); - if (capabilities != null) { - capabilities.setCapability(PLATFORM_NAME, IOS_PLATFORM); - } - return capabilities; - } - - class IOSAlert implements Alert { private final Alert alert; diff --git a/src/main/java/io/appium/java_client/windows/WindowsDriver.java b/src/main/java/io/appium/java_client/windows/WindowsDriver.java index acc1f4446..af559f12a 100644 --- a/src/main/java/io/appium/java_client/windows/WindowsDriver.java +++ b/src/main/java/io/appium/java_client/windows/WindowsDriver.java @@ -35,40 +35,40 @@ public class WindowsDriver FindsByWindowsAutomation { public WindowsDriver(HttpCommandExecutor executor, Capabilities capabilities) { - super(executor, substituteMobilePlatform(capabilities, WINDOWS)); + super(executor, updateDefaultPlatformName(capabilities, WINDOWS)); } public WindowsDriver(URL remoteAddress, Capabilities desiredCapabilities) { - super(remoteAddress, substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(remoteAddress, updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } public WindowsDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(remoteAddress, httpClientFactory, substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(remoteAddress, httpClientFactory, updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } public WindowsDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) { - super(service, substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(service, updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } public WindowsDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(service, httpClientFactory, substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(service, httpClientFactory, updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } public WindowsDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) { - super(builder, substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(builder, updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } public WindowsDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(builder, httpClientFactory, substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(builder, httpClientFactory, updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } public WindowsDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(httpClientFactory, updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } public WindowsDriver(Capabilities desiredCapabilities) { - super(substituteMobilePlatform(desiredCapabilities, WINDOWS)); + super(updateDefaultPlatformName(desiredCapabilities, WINDOWS)); } } From f8982afa4a9e6173fbdd1aff1a1b7421140839bd Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 28 Jun 2019 20:58:43 +0200 Subject: [PATCH 010/675] Add executeDriverScript command (#1165) --- .../io/appium/java_client/AppiumDriver.java | 3 +- .../java_client/ExecutesDriverScript.java | 71 +++++++++++++++++++ .../io/appium/java_client/MobileCommand.java | 3 + .../driverscripts/ScriptOptions.java | 66 +++++++++++++++++ .../java_client/driverscripts/ScriptType.java | 21 ++++++ .../driverscripts/ScriptValue.java | 49 +++++++++++++ .../android/ExecuteDriverScriptTest.java | 51 +++++++++++++ 7 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/appium/java_client/ExecutesDriverScript.java create mode 100644 src/main/java/io/appium/java_client/driverscripts/ScriptOptions.java create mode 100644 src/main/java/io/appium/java_client/driverscripts/ScriptType.java create mode 100644 src/main/java/io/appium/java_client/driverscripts/ScriptValue.java create mode 100644 src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 4fc4c49ee..c95224da0 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -65,7 +65,8 @@ */ @SuppressWarnings("unchecked") public class AppiumDriver - extends DefaultGenericMobileDriver implements ComparesImages, FindsByImage, FindsByCustom { + extends DefaultGenericMobileDriver implements ComparesImages, FindsByImage, FindsByCustom, + ExecutesDriverScript { private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true); // frequently used command parameters diff --git a/src/main/java/io/appium/java_client/ExecutesDriverScript.java b/src/main/java/io/appium/java_client/ExecutesDriverScript.java new file mode 100644 index 000000000..997b061a2 --- /dev/null +++ b/src/main/java/io/appium/java_client/ExecutesDriverScript.java @@ -0,0 +1,71 @@ +/* + * 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 io.appium.java_client.driverscripts.ScriptOptions; +import io.appium.java_client.driverscripts.ScriptValue; +import org.openqa.selenium.remote.Response; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; +import static io.appium.java_client.MobileCommand.EXECUTE_DRIVER_SCRIPT; + +public interface ExecutesDriverScript extends ExecutesMethod { + + /** + * Run a set of scripts in scope of the current session. + * This allows multiple web driver commands to be executed within one request + * and may significantly speed up the automation script performance in + * distributed client-server environments with high latency. + * Read http://appium.io/docs/en/commands/session/execute-driver for more details. + * + * @since Appium 1.14 + * @param script the web driver script to execute (it should + * be a valid webdriverio code snippet by default + * unless another option is provided) + * @param options additional scripting options + * @return The script result + * @throws org.openqa.selenium.WebDriverException if there was a failure while executing the script + */ + default ScriptValue executeDriverScript(String script, @Nullable ScriptOptions options) { + Map data = new HashMap<>(); + data.put("script", checkNotNull(script)); + if (options != null) { + data.putAll(options.build()); + } + Response response = execute(EXECUTE_DRIVER_SCRIPT, data); + //noinspection unchecked + Map value = (Map) response.getValue(); + //noinspection unchecked + return new ScriptValue(value.get("result"), (Map) value.get("logs")); + } + + /** + * Run a set of scripts in scope of the current session with default options. + * + * @since Appium 1.14 + * @param script the web driver script to execute (it should + * be a valid webdriverio code snippet) + * @return The script result + */ + default ScriptValue executeDriverScript(String script) { + return executeDriverScript(script, null); + } +} diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 4838a886a..4d2e3bffe 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -110,6 +110,7 @@ public class MobileCommand { protected static final String TOGGLE_AIRPLANE_MODE; protected static final String TOGGLE_DATA; protected static final String COMPARE_IMAGES; + protected static final String EXECUTE_DRIVER_SCRIPT; public static final Map commandRepository; @@ -184,6 +185,7 @@ public class MobileCommand { TOGGLE_AIRPLANE_MODE = "toggleFlightMode"; TOGGLE_DATA = "toggleData"; COMPARE_IMAGES = "compareImages"; + EXECUTE_DRIVER_SCRIPT = "executeDriverScript"; commandRepository = new HashMap<>(); commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset")); @@ -268,6 +270,7 @@ public class MobileCommand { commandRepository.put(TOGGLE_AIRPLANE_MODE, postC("/session/:sessionId/appium/device/toggle_airplane_mode")); commandRepository.put(TOGGLE_DATA, postC("/session/:sessionId/appium/device/toggle_data")); commandRepository.put(COMPARE_IMAGES, postC("/session/:sessionId/appium/compare_images")); + commandRepository.put(EXECUTE_DRIVER_SCRIPT, postC("/session/:sessionId/appium/execute_driver")); } /** diff --git a/src/main/java/io/appium/java_client/driverscripts/ScriptOptions.java b/src/main/java/io/appium/java_client/driverscripts/ScriptOptions.java new file mode 100644 index 000000000..15d7ddf36 --- /dev/null +++ b/src/main/java/io/appium/java_client/driverscripts/ScriptOptions.java @@ -0,0 +1,66 @@ +/* + * 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.driverscripts; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Optional.ofNullable; + + +public class ScriptOptions { + private ScriptType scriptType; + private Long timeoutMs; + + /** + * Sets the script type. + * + * @param type the actual script type + * @return self instance for chaining + */ + public ScriptOptions withScriptType(ScriptType type) { + this.scriptType = checkNotNull(type); + return this; + } + + /** + * Sets the script execution timeout. + * If this is not set then the maximum duration of the script + * is not limited (e. g. may block forever). + * + * @param timeoutMs the timeout in milliseconds + * @return self instance for chaining + */ + public ScriptOptions withTimeout(long timeoutMs) { + this.timeoutMs = timeoutMs; + return this; + } + + /** + * Builds a values map for further usage in HTTP requests to Appium. + * + * @return The map containing the provided options + */ + public Map build() { + final ImmutableMap.Builder builder = ImmutableMap.builder(); + ofNullable(scriptType).map(x -> builder.put("type", x.name().toLowerCase())); + ofNullable(timeoutMs).map(x -> builder.put("timeout", x)); + return builder.build(); + } +} diff --git a/src/main/java/io/appium/java_client/driverscripts/ScriptType.java b/src/main/java/io/appium/java_client/driverscripts/ScriptType.java new file mode 100644 index 000000000..42aa78833 --- /dev/null +++ b/src/main/java/io/appium/java_client/driverscripts/ScriptType.java @@ -0,0 +1,21 @@ +/* + * 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.driverscripts; + +public enum ScriptType { + WEBDRIVERIO +} diff --git a/src/main/java/io/appium/java_client/driverscripts/ScriptValue.java b/src/main/java/io/appium/java_client/driverscripts/ScriptValue.java new file mode 100644 index 000000000..3949feaa1 --- /dev/null +++ b/src/main/java/io/appium/java_client/driverscripts/ScriptValue.java @@ -0,0 +1,49 @@ +/* + * 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.driverscripts; + +import java.util.Map; + +public class ScriptValue { + private final Object result; + private final Map logs; + + public ScriptValue(Object result, Map logs) { + this.result = result; + this.logs = logs; + } + + /** + * The result of ExecuteDriverScript call. + * + * @return The actual returned value depends on the script content + */ + public Object getResult() { + return result; + } + + /** + * Retrieves logs mapping from ExecuteDriverScript call. + * + * @return Mapping keys are log levels, for example `warn` or + * `error` and the values are lists of strings that were printed + * by the script into the corresponding logging level + */ + public Map getLogs() { + return logs; + } +} diff --git a/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java b/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java new file mode 100644 index 000000000..5b8da2938 --- /dev/null +++ b/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java @@ -0,0 +1,51 @@ +/* + * 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.android; + +import io.appium.java_client.driverscripts.ScriptOptions; +import io.appium.java_client.driverscripts.ScriptType; +import io.appium.java_client.driverscripts.ScriptValue; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +public class ExecuteDriverScriptTest extends BaseAndroidTest { + + @Test + public void verifyBasicScriptExecution() { + String script = String.join("\n", Arrays.asList( + "const status = await driver.status();", + "console.warn('warning message');", + "return status;") + ); + ScriptValue value = driver.executeDriverScript(script, new ScriptOptions() + .withTimeout(5000) + .withScriptType(ScriptType.WEBDRIVERIO)); + //noinspection unchecked + assertNotNull(((Map) value.getResult()).get("build")); + //noinspection unchecked + assertThat(((List)value.getLogs().get("warn")).get(0), + is(equalTo("warning message"))); + } +} From 0a796983830613103180aeb9b434ea1fa748dd01 Mon Sep 17 00:00:00 2001 From: Takeshi Kishi Date: Mon, 1 Jul 2019 20:52:34 +0900 Subject: [PATCH 011/675] add the settings which introduced in appium 1.14 (#1166) * add the settings which introduced in appium 1.14 * add trackScrollEvents, keyboardAutocorrection, keyboardPrediction, getMatchedImageResult * fix javadocs * add tests * fix javadoc --- .../java/io/appium/java_client/Setting.java | 10 +++++++-- .../android/HasAndroidSettings.java | 14 ++++++++++++ .../java_client/ios/HasIOSSettings.java | 22 +++++++++++++++++++ .../java_client/android/SettingTest.java | 8 +++++++ .../appium/java_client/ios/SettingTest.java | 12 ++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/appium/java_client/Setting.java b/src/main/java/io/appium/java_client/Setting.java index 316015600..90197b4ce 100644 --- a/src/main/java/io/appium/java_client/Setting.java +++ b/src/main/java/io/appium/java_client/Setting.java @@ -18,7 +18,9 @@ /** * Enums defining constants for Appium Settings which can be set and toggled during a test session. - * https://appium.io/docs/en/advanced-concepts/settings/ + *
+ * + * https://appium.io/docs/en/advanced-concepts/settings/ */ public enum Setting { @@ -33,12 +35,15 @@ public enum Setting { NORMALIZE_TAG_NAMES("normalizeTagNames"), KEY_INJECTION_DELAY("keyInjectionDelay"), SHUTDOWN_ON_POWER_DISCONNECT("shutdownOnPowerDisconnect"), + TRACK_SCROLL_EVENTS("trackScrollEvents"), // iOS MJPEG_SERVER_SCREENSHOT_QUALITY("mjpegServerScreenshotQuality"), MJPEG_SERVER_FRAMERATE("mjpegServerFramerate"), SCREENSHOT_QUALITY("screenshotQuality"), NATIVE_WEB_TAP("nativeWebTap"), MJPEG_SCALING_FACTOR("mjpegScalingFactor"), + KEYBOARD_AUTOCORRECTION("keyboardAutocorrection"), + KEYBOARD_PREDICTION("keyboardPrediction"), // Android and iOS SHOULD_USE_COMPACT_RESPONSES("shouldUseCompactResponses"), ELEMENT_RESPONSE_ATTRIBUTES("elementResponseAttributes"), @@ -50,7 +55,8 @@ public enum Setting { CHECK_IMAGE_ELEMENT_STALENESS("checkForImageElementStaleness"), UPDATE_IMAGE_ELEMENT_POSITION("autoUpdateImageElementPosition"), FIX_IMAGE_TEMPLATE_SCALE("fixImageTemplateScale"), - DEFAULT_IMAGE_TEMPLATE_SCALE("defaultImageTemplateScale"); + DEFAULT_IMAGE_TEMPLATE_SCALE("defaultImageTemplateScale"), + GET_MATCHED_IMAGE_RESULT("getMatchedImageResult"); private final String name; diff --git a/src/main/java/io/appium/java_client/android/HasAndroidSettings.java b/src/main/java/io/appium/java_client/android/HasAndroidSettings.java index a3584c614..977377b42 100644 --- a/src/main/java/io/appium/java_client/android/HasAndroidSettings.java +++ b/src/main/java/io/appium/java_client/android/HasAndroidSettings.java @@ -177,4 +177,18 @@ default HasAndroidSettings shutdownOnPowerDisconnect(boolean enabled) { setSetting(Setting.SHUTDOWN_ON_POWER_DISCONNECT, enabled); return this; } + + /** + * Turn on or off the tracking of scroll events as they happen. + * If {@code true}, a field {@code lastScrollData} is added to the results of + * {@code getSession}, which can then be used to check on scroll progress. + * Turning this feature off significantly increases touch action performance. + * + * @param enabled Either true or false. The default value if true. + * @return self instance for chaining + */ + default HasAndroidSettings setTrackScrollEvents(boolean enabled) { + setSetting(Setting.TRACK_SCROLL_EVENTS, enabled); + return this; + } } diff --git a/src/main/java/io/appium/java_client/ios/HasIOSSettings.java b/src/main/java/io/appium/java_client/ios/HasIOSSettings.java index ad8179cdb..1eda46aa4 100644 --- a/src/main/java/io/appium/java_client/ios/HasIOSSettings.java +++ b/src/main/java/io/appium/java_client/ios/HasIOSSettings.java @@ -107,4 +107,26 @@ default HasIOSSettings setMjpegScalingFactor(int scale) { setSetting(Setting.MJPEG_SCALING_FACTOR, scale); return this; } + + /** + * Changes the 'Auto-Correction' preference in Keyboards setting. + * + * @param enabled Either true or false. Defaults to false when WDA starts as xctest. + * @return self instance for chaining + */ + default HasIOSSettings setKeyboardAutocorrection(boolean enabled) { + setSetting(Setting.KEYBOARD_AUTOCORRECTION, enabled); + return this; + } + + /** + * Changes the 'Predictive' preference in Keyboards setting. + * + * @param enabled Either true or false. Defaults to false when WDA starts as xctest. + * @return self instance for chaining + */ + default HasIOSSettings setKeyboardPrediction(boolean enabled) { + setSetting(Setting.KEYBOARD_PREDICTION, enabled); + return this; + } } 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 ac2850595..0cd0ac6f5 100644 --- a/src/test/java/io/appium/java_client/android/SettingTest.java +++ b/src/test/java/io/appium/java_client/android/SettingTest.java @@ -84,6 +84,14 @@ public class SettingTest extends BaseAndroidTest { .get(Setting.SHUTDOWN_ON_POWER_DISCONNECT.toString())); } + @Test public void testSetTrackScrollEvents() { + assertEquals(true, driver.getSettings() + .get(Setting.TRACK_SCROLL_EVENTS.toString())); + driver.setTrackScrollEvents(false); + assertEquals(false, driver.getSettings() + .get(Setting.TRACK_SCROLL_EVENTS.toString())); + } + private void assertJSONElementContains(Setting setting, long value) { assertEquals(driver.getSettings().get(setting.toString()), value); } diff --git a/src/test/java/io/appium/java_client/ios/SettingTest.java b/src/test/java/io/appium/java_client/ios/SettingTest.java index 16fd358df..b6d576585 100644 --- a/src/test/java/io/appium/java_client/ios/SettingTest.java +++ b/src/test/java/io/appium/java_client/ios/SettingTest.java @@ -71,5 +71,17 @@ public class SettingTest extends AppIOSTest { .get(Setting.MJPEG_SCALING_FACTOR.toString())); } + @Test public void testSetKeyboardAutocorrection() { + driver.setKeyboardAutocorrection(true); + assertEquals(true, driver.getSettings() + .get(Setting.KEYBOARD_AUTOCORRECTION.toString())); + } + + @Test public void testSetKeyboardPrediction() { + driver.setKeyboardPrediction(true); + assertEquals(true, driver.getSettings() + .get(Setting.KEYBOARD_PREDICTION.toString())); + } + } From bbfe0703bfaf1c9c4d1bfdbe94f24b8536860fa9 Mon Sep 17 00:00:00 2001 From: jayandran-Sampath Date: Tue, 2 Jul 2019 12:17:55 +0530 Subject: [PATCH 012/675] Code changes for getting all session details (#1167) * Code changes for getting all session details * Revert "Code changes for getting all session details" This reverts commit 76159eb0ea6bc5a4b343b2df10dcc8e30649db93. * Updated the comments and recommitting the changes * Organised import statement as per comments * Updated as per comments --- .../io/appium/java_client/HasSessionDetails.java | 15 +++++++++++++++ .../java/io/appium/java_client/MobileCommand.java | 3 +++ .../java_client/android/AndroidDriverTest.java | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/io/appium/java_client/HasSessionDetails.java b/src/main/java/io/appium/java_client/HasSessionDetails.java index b743363e5..1ae3f9f80 100644 --- a/src/main/java/io/appium/java_client/HasSessionDetails.java +++ b/src/main/java/io/appium/java_client/HasSessionDetails.java @@ -16,15 +16,18 @@ package io.appium.java_client; +import static io.appium.java_client.MobileCommand.GET_ALLSESSION; import static io.appium.java_client.MobileCommand.GET_SESSION; import static java.util.Optional.ofNullable; import static java.util.stream.Collectors.toMap; import static org.apache.commons.lang3.StringUtils.isBlank; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.openqa.selenium.remote.Response; +import java.util.List; import java.util.Map; import javax.annotation.Nullable; @@ -86,4 +89,16 @@ default boolean isBrowser() { return ofNullable(getSessionDetail("browserName")) .orElse(null) != null; } + + /** + * Get All Sessions details. + * + * @return List of Map objects with All Session Details. + */ + @SuppressWarnings("unchecked") + default List> getAllSessionDetails() { + Response response = execute(GET_ALLSESSION); + List> resultSet = List.class.cast(response.getValue()); + return ImmutableList.>builder().addAll(resultSet).build(); + } } diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 4d2e3bffe..aaf855468 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -111,6 +111,7 @@ public class MobileCommand { protected static final String TOGGLE_DATA; protected static final String COMPARE_IMAGES; protected static final String EXECUTE_DRIVER_SCRIPT; + protected static final String GET_ALLSESSION; public static final Map commandRepository; @@ -186,6 +187,7 @@ public class MobileCommand { TOGGLE_DATA = "toggleData"; COMPARE_IMAGES = "compareImages"; EXECUTE_DRIVER_SCRIPT = "executeDriverScript"; + GET_ALLSESSION = "getAllSessions"; commandRepository = new HashMap<>(); commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset")); @@ -271,6 +273,7 @@ public class MobileCommand { commandRepository.put(TOGGLE_DATA, postC("/session/:sessionId/appium/device/toggle_data")); commandRepository.put(COMPARE_IMAGES, postC("/session/:sessionId/appium/compare_images")); commandRepository.put(EXECUTE_DRIVER_SCRIPT, postC("/session/:sessionId/appium/execute_driver")); + commandRepository.put(GET_ALLSESSION, getC("/sessions")); } /** diff --git a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java index 65d086ad5..1f3c0ae00 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -314,5 +314,10 @@ public void getPerformanceDataTest() { public void getCurrentPackageTest() { assertEquals(APP_ID, driver.getCurrentPackage()); } + + @Test public void validateAllSessions() { + List> jsonMap = driver.getAllSessionDetails(); + assertNotNull(jsonMap); + } } From 121aa413a40f4e17893012b37adad27c64377539 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 6 Jul 2019 23:28:09 +0530 Subject: [PATCH 013/675] Apply Maven publish plugin and Release 7.1.0 --- build.gradle | 131 ++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 64 deletions(-) diff --git a/build.gradle b/build.gradle index 000a771e9..0100e5c1f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'java' apply plugin: 'idea' -apply plugin: 'maven' +apply plugin: 'maven-publish' apply plugin: 'eclipse' apply plugin: 'jacoco' apply plugin: 'checkstyle' @@ -8,9 +8,6 @@ apply plugin: 'signing' import org.apache.tools.ant.filters.* -group 'io.appium' -version '7.0.0' - repositories { jcenter() mavenCentral() @@ -115,83 +112,89 @@ checkstyle { } checkstyleMain.excludes = ['**/org/openqa/selenium/**'] -task javadocJar(type: Jar) { - classifier = 'javadoc' - from javadoc -} - task sourcesJar(type: Jar) { - classifier = 'sources' - from sourceSets.main.allSource -} - -artifacts { - archives javadocJar, sourcesJar + from sourceSets.main.allJava + archiveClassifier = 'sources' } -signing { - sign configurations.archives -} - -uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') { - authentication(userName: ossrhUsername, password: ossrhPassword) - } - - pom.project { - packaging 'jar' - name 'java-client' - description 'Java client for Appium Mobile Webdriver' - url 'http://appium.io' +task javadocJar(type: Jar) { + from javadoc + archiveClassifier = 'javadoc' +} + +javadoc { + options.addStringOption('encoding', 'UTF-8') +} + +publishing { + publications { + mavenJava(MavenPublication) { + groupId = 'io.appium' + artifactId = 'java-client' + version = '7.1.0' + from components.java + artifact sourcesJar + artifact javadocJar + pom { + name = 'java-client' + description = 'Java client for Appium Mobile Webdriver' + url = 'http://appium.io' developers { developer { - name 'Jonah Stiennon' - email 'jonahss@gmail.com' - url 'https://github.com/jonahss' - id 'jonahss' - }; + name = 'Jonah Stiennon' + email = 'jonahss@gmail.com' + url = 'https://github.com/jonahss' + id = 'jonahss' + } developer { - name 'Sergey Tikhomirov' - email 'tichomirovsergey@gmail.com' - url 'https://github.com/TikhomirovSergey' - id 'TikhomirovSergey' - }; + name = 'Sergey Tikhomirov' + email = 'tichomirovsergey@gmail.com' + url = 'https://github.com/TikhomirovSergey' + id = 'TikhomirovSergey' + } developer { - name 'Srinivasan Sekar' - email 'srinivasan.sekar1990@gmail.com' - url 'https://github.com/SrinivasanTarget' - id 'SrinivasanTarget' - }; + name = 'Srinivasan Sekar' + email = 'srinivasan.sekar1990@gmail.com' + url = 'https://github.com/SrinivasanTarget' + id = 'SrinivasanTarget' + } developer { - name 'Mykola Mokhnach' - url 'https://github.com/mykola-mokhnach' - id 'mykola-mokhnach' - }; + name = 'Mykola Mokhnach' + url = 'https://github.com/mykola-mokhnach' + id = 'mykola-mokhnach' + } } licenses { license { - name 'Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' + name = 'Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution = 'repo' } } scm { - url 'https://github.com/appium/java-client' - connection 'scm:git:ssh://git@github.com/appium/java-client.git' - developerConnection 'scm:git:ssh://git@github.com/appium/java-client.git' - tag 'HEAD' + url = 'https://github.com/appium/java-client' + connection = 'scm:git:ssh://git@github.com/appium/java-client.git' + developerConnection = 'scm:git:ssh://git@github.com/appium/java-client.git' + tag = 'HEAD' } } } } + repositories { + maven { + credentials { + username "$ossrhUsername" + password "$ossrhPassword" + } + def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/'" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + } + } +} + +signing { + sign publishing.publications.mavenJava } wrapper { @@ -233,4 +236,4 @@ task uiAutomationTest( type: Test ) { includeTestsMatching 'io.appium.java_client.android.ClipboardTest' includeTestsMatching '*.AndroidAppStringsTest' } -} +} \ No newline at end of file From 80fec4610133f73c28e1d21a1fc36d96d38ef1d9 Mon Sep 17 00:00:00 2001 From: Valery Yatsynovich Date: Sun, 7 Jul 2019 23:52:29 +0300 Subject: [PATCH 014/675] Fix CI: change task name: signArchives -> signMavenJavaPublication (#1172) --- .travis.yml | 4 ++-- azure-pipelines.yml | 2 +- jitpack.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3af8d0a80..062d09d79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ matrix: - extra-android-support - sys-img-armeabi-v7a-android-24 script: - - ./gradlew clean build -x signArchives -x test -x checkstyleTest + - ./gradlew clean build -x signMavenJavaPublication -x test -x checkstyleTest before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock @@ -25,4 +25,4 @@ before_cache: cache: directories: - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ \ No newline at end of file + - $HOME/.gradle/wrapper/ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2aaa45a52..e374442f0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -54,4 +54,4 @@ steps: jdkArchitectureOption: 'x64' publishJUnitResults: true tasks: 'build' - options: 'xcuiTest uiAutomationTest -x checkstyleTest -x test -x signArchives' + options: 'xcuiTest uiAutomationTest -x checkstyleTest -x test -x signMavenJavaPublication' diff --git a/jitpack.yml b/jitpack.yml index f97ffa75d..fe6c1ec3c 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,4 +1,4 @@ jdk: - openjdk8 install: - - ./gradlew clean install -x test -x signArchives + - ./gradlew clean install -x test -x signMavenJavaPublication From f8361149fd84d9b914044028d85d5deec0aac4d2 Mon Sep 17 00:00:00 2001 From: Valery Yatsynovich Date: Mon, 8 Jul 2019 10:58:09 +0300 Subject: [PATCH 015/675] Update dependencies (#1171) --- build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 0100e5c1f..13885a3bf 100644 --- a/build.gradle +++ b/build.gradle @@ -64,13 +64,13 @@ dependencies { force = true } compile 'com.google.code.gson:gson:2.8.5' - compile 'org.apache.httpcomponents:httpclient:4.5.8' - compile 'cglib:cglib:3.2.10' + compile 'org.apache.httpcomponents:httpclient:4.5.9' + compile 'cglib:cglib:3.2.12' compile 'commons-validator:commons-validator:1.6' compile 'org.apache.commons:commons-lang3:3.9' compile 'commons-io:commons-io:2.6' - compile 'org.springframework:spring-context:5.1.6.RELEASE' - compile 'org.aspectj:aspectjweaver:1.9.3' + compile 'org.springframework:spring-context:5.1.8.RELEASE' + compile 'org.aspectj:aspectjweaver:1.9.4' compile 'org.slf4j:slf4j-api:1.7.26' testCompile 'junit:junit:4.12' @@ -236,4 +236,4 @@ task uiAutomationTest( type: Test ) { includeTestsMatching 'io.appium.java_client.android.ClipboardTest' includeTestsMatching '*.AndroidAppStringsTest' } -} \ No newline at end of file +} From cb498a3cdf62aa939dfa2731afaefe72cdaa4b09 Mon Sep 17 00:00:00 2001 From: Valery Yatsynovich Date: Mon, 8 Jul 2019 10:59:22 +0300 Subject: [PATCH 016/675] Checkstyle updates (#1170) --- build.gradle | 2 +- .../appium/java_client/pagefactory/AndroidFindByAllSet.java | 4 +++- .../appium/java_client/pagefactory/AndroidFindByChainSet.java | 4 +++- .../io/appium/java_client/pagefactory/AndroidFindBySet.java | 4 +++- .../appium/java_client/pagefactory/WindowsFindByAllSet.java | 4 +++- .../appium/java_client/pagefactory/WindowsFindByChainSet.java | 4 +++- .../io/appium/java_client/pagefactory/WindowsFindBySet.java | 4 +++- .../appium/java_client/pagefactory/iOSXCUITFindByAllSet.java | 4 +++- .../java_client/pagefactory/iOSXCUITFindByChainSet.java | 4 +++- .../io/appium/java_client/pagefactory/iOSXCUITFindBySet.java | 4 +++- 10 files changed, 28 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 13885a3bf..5a354d816 100644 --- a/build.gradle +++ b/build.gradle @@ -105,7 +105,7 @@ tasks.withType(JacocoReport) { jacocoTestReport.dependsOn test checkstyle { - toolVersion = '8.17' + toolVersion = '8.22' configFile = file("$projectDir/google-style.xml") showViolations = true ignoreFailures = false diff --git a/src/main/java/io/appium/java_client/pagefactory/AndroidFindByAllSet.java b/src/main/java/io/appium/java_client/pagefactory/AndroidFindByAllSet.java index 40e49415a..ab6afda28 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AndroidFindByAllSet.java +++ b/src/main/java/io/appium/java_client/pagefactory/AndroidFindByAllSet.java @@ -15,8 +15,10 @@ @Retention(value = RUNTIME) public @interface AndroidFindByAllSet { /** + * An array which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link AndroidFindAll} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ AndroidFindAll[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/AndroidFindByChainSet.java b/src/main/java/io/appium/java_client/pagefactory/AndroidFindByChainSet.java index bf1958767..365146650 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AndroidFindByChainSet.java +++ b/src/main/java/io/appium/java_client/pagefactory/AndroidFindByChainSet.java @@ -15,8 +15,10 @@ @Retention(value = RUNTIME) public @interface AndroidFindByChainSet { /** + * An array of which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link io.appium.java_client.pagefactory.AndroidFindBys} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ AndroidFindBys[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/AndroidFindBySet.java b/src/main/java/io/appium/java_client/pagefactory/AndroidFindBySet.java index 08be7d053..6e35ebccd 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AndroidFindBySet.java +++ b/src/main/java/io/appium/java_client/pagefactory/AndroidFindBySet.java @@ -31,8 +31,10 @@ @Retention(value = RUNTIME) public @interface AndroidFindBySet { /** + * An array of which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link io.appium.java_client.pagefactory.AndroidFindBy} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ AndroidFindBy[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/WindowsFindByAllSet.java b/src/main/java/io/appium/java_client/pagefactory/WindowsFindByAllSet.java index adbad0864..9a1e2f3cd 100644 --- a/src/main/java/io/appium/java_client/pagefactory/WindowsFindByAllSet.java +++ b/src/main/java/io/appium/java_client/pagefactory/WindowsFindByAllSet.java @@ -15,8 +15,10 @@ @Retention(value = RUNTIME) public @interface WindowsFindByAllSet { /** + * An array of which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link WindowsFindAll} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ WindowsFindAll[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/WindowsFindByChainSet.java b/src/main/java/io/appium/java_client/pagefactory/WindowsFindByChainSet.java index b8a5bc03d..583d0f5d5 100644 --- a/src/main/java/io/appium/java_client/pagefactory/WindowsFindByChainSet.java +++ b/src/main/java/io/appium/java_client/pagefactory/WindowsFindByChainSet.java @@ -15,8 +15,10 @@ @Retention(value = RUNTIME) public @interface WindowsFindByChainSet { /** + * An array of which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link WindowsFindBys} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ WindowsFindBys[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/WindowsFindBySet.java b/src/main/java/io/appium/java_client/pagefactory/WindowsFindBySet.java index edf7de758..5efd79322 100644 --- a/src/main/java/io/appium/java_client/pagefactory/WindowsFindBySet.java +++ b/src/main/java/io/appium/java_client/pagefactory/WindowsFindBySet.java @@ -31,8 +31,10 @@ @Retention(value = RUNTIME) public @interface WindowsFindBySet { /** + * An array ofwhich builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link WindowsFindBy} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ WindowsFindBy[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByAllSet.java b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByAllSet.java index a0adcf8f2..0bb769ea7 100644 --- a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByAllSet.java +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByAllSet.java @@ -15,8 +15,10 @@ @Retention(value = RUNTIME) public @interface iOSXCUITFindByAllSet { /** + * An array of which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link io.appium.java_client.pagefactory.iOSXCUITFindAll} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ iOSXCUITFindAll[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByChainSet.java b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByChainSet.java index 056931c8a..2b5fc28de 100644 --- a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByChainSet.java +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindByChainSet.java @@ -15,8 +15,10 @@ @Retention(value = RUNTIME) public @interface iOSXCUITFindByChainSet { /** + * An array of which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link io.appium.java_client.pagefactory.iOSXCUITFindBys} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ iOSXCUITFindBys[] value(); } diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBySet.java b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBySet.java index 2d3b0c02b..f1fea5a89 100644 --- a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBySet.java +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBySet.java @@ -26,8 +26,10 @@ @Retention(RUNTIME) @Target({FIELD, TYPE}) public @interface iOSXCUITFindBySet { /** + * An array of which builds a sequence of the chained searching for elements or a set of possible locators. + * * @return an array of {@link iOSXCUITFindBy} which builds a sequence of - * the chained searching for elements or a set of possible locators + * the chained searching for elements or a set of possible locators */ iOSXCUITFindBy[] value(); } From f57e7c073bcbd9b02094441a6b6f228ecd49e9a1 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2019 18:22:29 +0530 Subject: [PATCH 017/675] Bump webdrivermanager from 3.4.0 to 3.6.1 (#1176) Bumps [webdrivermanager](https://github.com/bonigarcia/webdrivermanager) from 3.4.0 to 3.6.1. - [Release notes](https://github.com/bonigarcia/webdrivermanager/releases) - [Changelog](https://github.com/bonigarcia/webdrivermanager/blob/master/CHANGELOG.md) - [Commits](https://github.com/bonigarcia/webdrivermanager/compare/webdrivermanager-3.4.0...webdrivermanager-3.6.1) Signed-off-by: dependabot-preview[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5a354d816..5a7739815 100644 --- a/build.gradle +++ b/build.gradle @@ -75,7 +75,7 @@ dependencies { testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest:2.1' - testCompile (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.4.0') { + testCompile (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.6.1') { exclude group: 'org.seleniumhq.selenium' } } From c2bf584ae8dfeaf1d2520deee22c49bb594c6dd6 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2019 10:34:38 +0530 Subject: [PATCH 018/675] Bump shadow from 2.0.2 to 5.1.0 (#1174) Bumps shadow from 2.0.2 to 5.1.0. Signed-off-by: dependabot-preview[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5a7739815..17360cd42 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ buildscript { } dependencies { classpath 'org.owasp:dependency-check-gradle:1.4.0' - classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2' + classpath 'com.github.jengelman.gradle.plugins:shadow:5.1.0' } } From 45836768e9d4666375a4c8d9c70e72e6c52a588f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2019 14:39:18 +0530 Subject: [PATCH 019/675] Bump ecj from 3.16.0 to 3.18.0 (#1173) Bumps ecj from 3.16.0 to 3.18.0. Signed-off-by: dependabot-preview[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 17360cd42..969356784 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ configurations { } dependencies { - ecj 'org.eclipse.jdt:ecj:3.16.0' + ecj 'org.eclipse.jdt:ecj:3.18.0' } compileJava { From 7b3db36d028f61f84901459d25118750ef0af358 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2019 17:32:43 +0530 Subject: [PATCH 020/675] Bump dependency-check-gradle from 1.4.0 to 5.1.0 (#1175) Bumps [dependency-check-gradle](https://github.com/jeremylong/dependency-check-gradle) from 1.4.0 to 5.1.0. - [Release notes](https://github.com/jeremylong/dependency-check-gradle/releases) - [Commits](https://github.com/jeremylong/dependency-check-gradle/compare/v1.4.0...v5.1.0) Signed-off-by: dependabot-preview[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 969356784..78ba42348 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'org.owasp:dependency-check-gradle:1.4.0' + classpath 'org.owasp:dependency-check-gradle:5.1.0' classpath 'com.github.jengelman.gradle.plugins:shadow:5.1.0' } } From 20fc505a8b9614055a7533177f60ca099ab136ed Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Wed, 10 Jul 2019 23:35:25 +0530 Subject: [PATCH 021/675] Update changelog in readme --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index df8b7bb8c..f5bf5e592 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,41 @@ dependencies { ``` ## Changelog +*7.1.0* +- **[ENHANCEMENTS]** + - Added an ability to get all the session details. [#1167 ](https://github.com/appium/java-client/pull/1167) + - `TRACK_SCROLL_EVENTS`, `ALLOW_INVISIBLE_ELEMENTS`, `ENABLE_NOTIFICATION_LISTENER`, + `NORMALIZE_TAG_NAMES` and `SHUTDOWN_ON_POWER_DISCONNECT` Android Settings were added. + - `KEYBOARD_AUTOCORRECTION`, `MJPEG_SCALING_FACTOR`, + `MJPEG_SERVER_SCREENSHOT_QUALITY`, `MJPEG_SERVER_FRAMERATE`, `SCREENSHOT_QUALITY` + and `KEYBOARD_PREDICTION` iOS Settings were added. + - `GET_MATCHED_IMAGE_RESULT`, `FIX_IMAGE_TEMPLATE_SCALE`, + `SHOULD_USE_COMPACT_RESPONSES`, `ELEMENT_RESPONSE_ATTRIBUTES` and + `DEFAULT_IMAGE_TEMPLATE_SCALE` settings were added for both Android and iOS [#1166](https://github.com/appium/java-client/pull/1166), [#1156 ](https://github.com/appium/java-client/pull/1156) and [#1120](https://github.com/appium/java-client/pull/1120) + - The new interface `io.appium.java_client.ExecutesDriverScript ` was added. [#1165](https://github.com/appium/java-client/pull/1165) + - Added an ability to get status of appium server. [#1153 ](https://github.com/appium/java-client/pull/1153) + - `tvOS` platform support was added. [#1142 ](https://github.com/appium/java-client/pull/1142) + - The new interface `io.appium.java_client. FindsByAndroidDataMatcher` was added. [#1106](https://github.com/appium/java-client/pull/1106) + - The selector strategy `io.appium.java_client.MobileBy.ByAndroidDataMatcher` was added. [#1106](https://github.com/appium/java-client/pull/1106) + - Selendroid for android and UIAutomation for iOS are removed. [#1077 ](https://github.com/appium/java-client/pull/1077) + - **[BUG FIX]** Platform Name enforced on driver creation is avoided now. [#1164 ](https://github.com/appium/java-client/pull/1164) + - **[BUG FIX]** Send both signalStrengh and signalStrength for `GSM_SIGNAL`. [#1115 ](https://github.com/appium/java-client/pull/1115) + - **[BUG FIX]** Null pointer exceptions when calling getCapabilities is handled better. [#1094 ](https://github.com/appium/java-client/pull/1094) + +- **[DEPENDENCY UPDATES]** + - `org.seleniumhq.selenium:selenium-java` was updated to 4.0.0-alpha-1. + - `org.aspectj:aspectjweaver` was updated to 1.9.4. + - `org.apache.httpcomponents:httpclient` was updated to 4.5.9. + - `cglib:cglib` was updated to 3.2.12. + - `org.springframework:spring-context` was updated to 5.1.8.RELEASE. + - `io.github.bonigarcia:webdrivermanager` was updated to 3.6.1. + - `org.eclipse.jdt:ecj` was updated to 3.18.0. + - `com.github.jengelman.gradle.plugins:shadow` was updated to 5.1.0. + - `checkstyle` was updated to 8.22. + - `gradle` was updated to 5.4. + - `dependency-check-gradle` was updated to 5.1.0. + - `org.slf4j:slf4j-api` was updated to 1.7.26. + - `org.apache.commons:commons-lang3` was updated to 3.9. *7.0.0* - **[ENHANCEMENTS]** From 891636ad2bb8d97ec6e0ad876843b466f8d152c5 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sat, 13 Jul 2019 16:15:21 +0200 Subject: [PATCH 022/675] Add videoFilters property to the video recording params (#1180) --- .../ios/IOSStartScreenRecordingOptions.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/io/appium/java_client/ios/IOSStartScreenRecordingOptions.java b/src/main/java/io/appium/java_client/ios/IOSStartScreenRecordingOptions.java index 2835b807a..ff45f7e08 100644 --- a/src/main/java/io/appium/java_client/ios/IOSStartScreenRecordingOptions.java +++ b/src/main/java/io/appium/java_client/ios/IOSStartScreenRecordingOptions.java @@ -31,6 +31,7 @@ public class IOSStartScreenRecordingOptions private String videoType; private String videoQuality; private String videoScale; + private String videoFilters; private Integer fps; public static IOSStartScreenRecordingOptions startScreenRecordingOptions() { @@ -82,6 +83,7 @@ public IOSStartScreenRecordingOptions withFps(int fps) { /** * The scaling value to apply. Read https://trac.ffmpeg.org/wiki/Scaling for possible values. * No scale is applied by default. + * If filters are set then the scale setting is effectively ignored. * * @since Appium 1.10.0 * @param videoScale ffmpeg-compatible scale format specifier. @@ -106,6 +108,21 @@ public IOSStartScreenRecordingOptions withTimeLimit(Duration timeLimit) { return super.withTimeLimit(timeLimit); } + /** + * The FFMPEG video filters to apply. These filters allow to scale, flip, rotate and do many + * other useful transformations on the source video stream. The format of the property + * must comply with https://ffmpeg.org/ffmpeg-filters.html. + * + * @since Appium 1.15 + * @param filters One or more filters to apply to the resulting video stream, + * for example "transpose=1" to rotate the resulting video 90 degrees clockwise. + * @return self instance for chaining. + */ + public IOSStartScreenRecordingOptions withVideoFilters(String filters) { + this.videoFilters = filters; + return this; + } + @Override public Map build() { final ImmutableMap.Builder builder = ImmutableMap.builder(); @@ -113,6 +130,7 @@ public Map build() { ofNullable(videoType).map(x -> builder.put("videoType", x)); ofNullable(videoQuality).map(x -> builder.put("videoQuality", x)); ofNullable(videoScale).map(x -> builder.put("videoScale", x)); + ofNullable(videoFilters).map(x -> builder.put("videoFilters", x)); ofNullable(fps).map(x -> builder.put("videoFps", x)); return builder.build(); } From ac6723716abf54998ae0b1bf0d7a83e9f45433d3 Mon Sep 17 00:00:00 2001 From: jayandran-Sampath Date: Sun, 28 Jul 2019 09:08:38 +0530 Subject: [PATCH 023/675] Lombok Library Update (#1193) * Code changes for getting all session details * Revert "Code changes for getting all session details" This reverts commit 76159eb0ea6bc5a4b343b2df10dcc8e30649db93. * Updated the comments and recommitting the changes * Organised import statement as per comments * Updated as per comments * Code Changes for Lombok Plugin * Code Changes for introducing Lombok Library * as per comments, removed TestCompile & TestAnnotationProcessor --- build.gradle | 7 +- .../appium/java_client/AppiumCommandInfo.java | 14 +- .../appium/java_client/AppiumFluentWait.java | 56 +++--- .../java/io/appium/java_client/MobileBy.java | 12 +- .../appium/java_client/ScreenshotState.java | 34 ++-- .../appium/java_client/android/Activity.java | 172 +----------------- .../driverscripts/ScriptValue.java | 23 +-- .../imagecomparison/ComparisonResult.java | 8 +- .../builder/AnnotatedElementContainer.java | 14 +- .../service/local/Slf4jLogMessageContext.java | 28 ++- 10 files changed, 83 insertions(+), 285 deletions(-) diff --git a/build.gradle b/build.gradle index 78ba42348..04a68df9f 100644 --- a/build.gradle +++ b/build.gradle @@ -29,10 +29,12 @@ apply plugin: 'com.github.johnrengelman.shadow' configurations { ecj + lombok } dependencies { ecj 'org.eclipse.jdt:ecj:3.18.0' + lombok 'org.projectlombok:lombok:1.18.8' } compileJava { @@ -40,15 +42,18 @@ compileJava { targetCompatibility = 1.8 def ecjJar = configurations.ecj.singleFile + def lombokjar = configurations.lombok.singleFile options.fork = true - options.fork executable: 'java', jvmArgs: [ '-cp', ecjJar.path, 'org.eclipse.jdt.internal.compiler.batch.Main' ] + options.fork executable: 'java', jvmArgs: [ '-javaagent:'+lombokjar.path+'=ECJ', '-jar', ecjJar.path, '-cp', lombokjar.path] options.define compilerArgs: [ '-encoding', 'utf-8' ] } dependencies { + compileOnly('org.projectlombok:lombok:1.18.8') + annotationProcessor('org.projectlombok:lombok:1.18.8') compile ("org.seleniumhq.selenium:selenium-java:${project.property('selenium.version')}") { force = true diff --git a/src/main/java/io/appium/java_client/AppiumCommandInfo.java b/src/main/java/io/appium/java_client/AppiumCommandInfo.java index 7c6d0d43f..cea6016d5 100644 --- a/src/main/java/io/appium/java_client/AppiumCommandInfo.java +++ b/src/main/java/io/appium/java_client/AppiumCommandInfo.java @@ -16,12 +16,14 @@ package io.appium.java_client; +import lombok.AccessLevel; +import lombok.Getter; import org.openqa.selenium.remote.CommandInfo; import org.openqa.selenium.remote.http.HttpMethod; public class AppiumCommandInfo extends CommandInfo { - private final String url; - private final HttpMethod method; + @Getter(AccessLevel.PUBLIC) private final String url; + @Getter(AccessLevel.PUBLIC) private final HttpMethod method; /** * It conntains method and URL of the command. @@ -34,12 +36,4 @@ public AppiumCommandInfo(String url, HttpMethod method) { this.url = url; this.method = method; } - - public String getUrl() { - return url; - } - - public HttpMethod getMethod() { - return method; - } } diff --git a/src/main/java/io/appium/java_client/AppiumFluentWait.java b/src/main/java/io/appium/java_client/AppiumFluentWait.java index 435a87863..8f197ef47 100644 --- a/src/main/java/io/appium/java_client/AppiumFluentWait.java +++ b/src/main/java/io/appium/java_client/AppiumFluentWait.java @@ -18,6 +18,8 @@ import com.google.common.base.Throwables; +import lombok.AccessLevel; +import lombok.Getter; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.support.ui.FluentWait; @@ -35,61 +37,45 @@ public class AppiumFluentWait extends FluentWait { private Function pollingStrategy = null; public static class IterationInfo { - private final long number; - private final Duration elapsed; - private final Duration total; - private final Duration interval; - - /** - * The class is used to represent information about a single loop iteration in {@link #until(Function)} - * method. - * - * @param number loop iteration number, starts from 1 - * @param elapsed the amount of elapsed time since the loop started - * @param total the amount of total time to run the loop - * @param interval the default time interval for each loop iteration - */ - public IterationInfo(long number, Duration elapsed, Duration total, Duration interval) { - this.number = number; - this.elapsed = elapsed; - this.total = total; - this.interval = interval; - } - /** * The current iteration number. * * @return current iteration number. It starts from 1 */ - public long getNumber() { - return number; - } - + @Getter(AccessLevel.PUBLIC) private final long number; /** * The amount of elapsed time. * * @return the amount of elapsed time */ - public Duration getElapsed() { - return elapsed; - } - + @Getter(AccessLevel.PUBLIC) private final Duration elapsed; /** * The amount of total time. * * @return the amount of total time */ - public Duration getTotal() { - return total; - } - + @Getter(AccessLevel.PUBLIC) private final Duration total; /** * The current interval. * * @return The actual value of current interval or the default one if it is not set */ - public Duration getInterval() { - return interval; + @Getter(AccessLevel.PUBLIC) private final Duration interval; + + /** + * The class is used to represent information about a single loop iteration in {@link #until(Function)} + * method. + * + * @param number loop iteration number, starts from 1 + * @param elapsed the amount of elapsed time since the loop started + * @param total the amount of total time to run the loop + * @param interval the default time interval for each loop iteration + */ + public IterationInfo(long number, Duration elapsed, Duration total, Duration interval) { + this.number = number; + this.elapsed = elapsed; + this.total = total; + this.interval = interval; } } diff --git a/src/main/java/io/appium/java_client/MobileBy.java b/src/main/java/io/appium/java_client/MobileBy.java index cd7b49f5c..c04af3ea1 100644 --- a/src/main/java/io/appium/java_client/MobileBy.java +++ b/src/main/java/io/appium/java_client/MobileBy.java @@ -16,6 +16,8 @@ package io.appium.java_client; +import lombok.AccessLevel; +import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; import org.openqa.selenium.SearchContext; @@ -31,7 +33,7 @@ public abstract class MobileBy extends By { private static final String ERROR_TEXT = "The class %s of the given context " + "doesn't implement %s nor %s. Sorry. It is impossible to find something."; - private final String locatorString; + @Getter(AccessLevel.PROTECTED) private final String locatorString; private final MobileSelector selector; private static IllegalArgumentException formIllegalArgumentException(Class givenClass, @@ -48,19 +50,15 @@ protected MobileBy(MobileSelector selector, String locatorString) { this.selector = selector; } - protected String getLocatorString() { - return locatorString; - } - @SuppressWarnings("unchecked") @Override public List findElements(SearchContext context) { return (List) ((FindsByFluentSelector) context) - .findElements(selector.toString(), getLocatorString()); + .findElements(selector.toString(), getLocatorString()); } @Override public WebElement findElement(SearchContext context) { return ((FindsByFluentSelector) context) - .findElement(selector.toString(), getLocatorString()); + .findElement(selector.toString(), getLocatorString()); } /** diff --git a/src/main/java/io/appium/java_client/ScreenshotState.java b/src/main/java/io/appium/java_client/ScreenshotState.java index 2c72355b8..5645b79e2 100644 --- a/src/main/java/io/appium/java_client/ScreenshotState.java +++ b/src/main/java/io/appium/java_client/ScreenshotState.java @@ -16,6 +16,11 @@ package io.appium.java_client; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Optional.ofNullable; @@ -30,14 +35,20 @@ import javax.imageio.ImageIO; +@Accessors(chain = true) public class ScreenshotState { private static final Duration DEFAULT_INTERVAL_MS = Duration.ofMillis(500); private BufferedImage previousScreenshot; private final Supplier stateProvider; private final ComparesImages comparator; - - private Duration comparisonInterval = DEFAULT_INTERVAL_MS; + /** + * Gets the interval value in ms between similarity verification rounds in verify* methods. + * + * @param comparisonInterval interval value. 500 ms by default + * @return current interval value in ms + */ + @Getter(AccessLevel.PUBLIC) @Setter(AccessLevel.PUBLIC) private Duration comparisonInterval = DEFAULT_INTERVAL_MS; /** * The class constructor accepts two arguments. The first one is image comparator, the second @@ -79,25 +90,6 @@ public ScreenshotState(ComparesImages comparator) { this(comparator, null); } - /** - * Gets the interval value in ms between similarity verification rounds in verify* methods. - * - * @return current interval value in ms - */ - public Duration getComparisonInterval() { - return comparisonInterval; - } - - /** - * Sets the interval between similarity verification rounds in verify* methods. - * - * @param comparisonInterval interval value. 500 ms by default - * @return self instance for chaining - */ - public ScreenshotState setComparisonInterval(Duration comparisonInterval) { - this.comparisonInterval = comparisonInterval; - return this; - } /** * Call this method to save the initial screenshot state. diff --git a/src/main/java/io/appium/java_client/android/Activity.java b/src/main/java/io/appium/java_client/android/Activity.java index 790fad11b..da957d746 100644 --- a/src/main/java/io/appium/java_client/android/Activity.java +++ b/src/main/java/io/appium/java_client/android/Activity.java @@ -1,11 +1,17 @@ package io.appium.java_client.android; +import lombok.Data; +import lombok.experimental.Accessors; +import okhttp3.Interceptor; + import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang3.StringUtils.isBlank; /** * This is a simple POJO class to support the {@link StartsActivity}. */ +@Accessors(chain = true) +@Data public class Activity { private final String appPackage; private final String appActivity; @@ -33,170 +39,4 @@ public Activity(String appPackage, String appActivity) { this.stopApp = true; } - /** - * Gets the app package value. - * - * @return The app package value. - */ - public String getAppPackage() { - return appPackage; - } - - /** - * Gets the app activity value. - * - * @return The app activity value. - */ - public String getAppActivity() { - return appActivity; - } - - /** - * Gets the app wait package value. - * - * @return The app wait package value. - */ - public String getAppWaitPackage() { - return appWaitPackage; - } - - /** - * Sets the app wait package value. - * - * @param appWaitPackage The app wait package value. - * @return self reference - */ - public Activity setAppWaitPackage(String appWaitPackage) { - this.appWaitPackage = appWaitPackage; - return this; - } - - /** - * Gets the app wait activity value. - * - * @return The app wait activity value. - */ - public String getAppWaitActivity() { - return appWaitActivity; - } - - /** - * Sets the app wait activity value. - * - * @param appWaitActivity The app wait activity value. - * @return self reference - */ - public Activity setAppWaitActivity(String appWaitActivity) { - this.appWaitActivity = appWaitActivity; - return this; - } - - /** - * Gets the intent action value. - * - * @return The intent action value. - */ - public String getIntentAction() { - return intentAction; - } - - /** - * Sets the intent action value. - * - * @param intentAction The intent action value. - * @return self reference - */ - public Activity setIntentAction(String intentAction) { - this.intentAction = intentAction; - return this; - } - - /** - * Gets the intent category value. - * - * @return The intent category value. - */ - public String getIntentCategory() { - return intentCategory; - } - - /** - * Sets the intent category value. - * - * @param intentCategory The intent category value. - * @return self reference - */ - public Activity setIntentCategory(String intentCategory) { - this.intentCategory = intentCategory; - return this; - } - - /** - * Gets the intent flags value. - * - * @return The intent flags value. - */ - public String getIntentFlags() { - return intentFlags; - } - - /** - * Sets the intent flags value. - * - * @param intentFlags The intent flags value. - * @return self reference - */ - public Activity setIntentFlags(String intentFlags) { - this.intentFlags = intentFlags; - return this; - } - - /** - * Gets the optional intent arguments value. - * - * @return The optional intent arguments value. - */ - public String getOptionalIntentArguments() { - return optionalIntentArguments; - } - - /** - * Sets the optional intent arguments value. - * - * @param optionalIntentArguments The optional intent arguments value. - * @return self reference - */ - public Activity setOptionalIntentArguments(String optionalIntentArguments) { - this.optionalIntentArguments = optionalIntentArguments; - return this; - } - - /** - * Gets the stop app value. - * - * @return The stop app value. - */ - public boolean isStopApp() { - return stopApp; - } - - /** - * Sets the stop app value. - * - * @param stopApp The stop app value. - * @return self reference - */ - public Activity setStopApp(boolean stopApp) { - this.stopApp = stopApp; - return this; - } - - @Override public String toString() { - return "Activity{" + "appPackage='" + appPackage + '\'' + ", appActivity='" + appActivity - + '\'' + ", appWaitPackage='" + appWaitPackage + '\'' + ", appWaitActivity='" - + appWaitActivity + '\'' + ", intentAction='" + intentAction + '\'' - + ", intentCategory='" + intentCategory + '\'' + ", intentFlags='" + intentFlags + '\'' - + ", optionalIntentArguments='" + optionalIntentArguments + '\'' + ", stopApp=" - + stopApp + '}'; - } } diff --git a/src/main/java/io/appium/java_client/driverscripts/ScriptValue.java b/src/main/java/io/appium/java_client/driverscripts/ScriptValue.java index 3949feaa1..934cd670d 100644 --- a/src/main/java/io/appium/java_client/driverscripts/ScriptValue.java +++ b/src/main/java/io/appium/java_client/driverscripts/ScriptValue.java @@ -16,26 +16,18 @@ package io.appium.java_client.driverscripts; +import lombok.AccessLevel; +import lombok.Getter; + import java.util.Map; public class ScriptValue { - private final Object result; - private final Map logs; - - public ScriptValue(Object result, Map logs) { - this.result = result; - this.logs = logs; - } - /** * The result of ExecuteDriverScript call. * * @return The actual returned value depends on the script content */ - public Object getResult() { - return result; - } - + @Getter(AccessLevel.PUBLIC) private final Object result; /** * Retrieves logs mapping from ExecuteDriverScript call. * @@ -43,7 +35,10 @@ public Object getResult() { * `error` and the values are lists of strings that were printed * by the script into the corresponding logging level */ - public Map getLogs() { - return logs; + @Getter(AccessLevel.PUBLIC) private final Map logs; + + public ScriptValue(Object result, Map logs) { + this.result = result; + this.logs = logs; } } diff --git a/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java b/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java index de086251a..bd0cad7c5 100644 --- a/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java +++ b/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java @@ -16,6 +16,8 @@ package io.appium.java_client.imagecomparison; +import lombok.AccessLevel; +import lombok.Getter; import org.apache.commons.codec.binary.Base64; import org.openqa.selenium.Point; @@ -31,16 +33,12 @@ public abstract class ComparisonResult { private static final String VISUALIZATION = "visualization"; - private final Map commandResult; + @Getter(AccessLevel.PROTECTED) private final Map commandResult; public ComparisonResult(Map commandResult) { this.commandResult = commandResult; } - protected Map getCommandResult() { - return this.commandResult; - } - /** * Verifies if the corresponding property is present in the commend result * and throws an exception if not. diff --git a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AnnotatedElementContainer.java b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AnnotatedElementContainer.java index 6db68c8c9..8b4d4957b 100644 --- a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AnnotatedElementContainer.java +++ b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AnnotatedElementContainer.java @@ -16,20 +16,16 @@ package io.appium.java_client.pagefactory.bys.builder; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + import java.lang.reflect.AnnotatedElement; /** * This is the POJO for the setting/getting of an AnnotatedElement instances. */ public class AnnotatedElementContainer { + @Getter(AccessLevel.PUBLIC) @Setter(AccessLevel.PACKAGE) private AnnotatedElement annotated; - - - public AnnotatedElement getAnnotated() { - return annotated; - } - - void setAnnotated(AnnotatedElement annotated) { - this.annotated = annotated; - } } diff --git a/src/main/java/io/appium/java_client/service/local/Slf4jLogMessageContext.java b/src/main/java/io/appium/java_client/service/local/Slf4jLogMessageContext.java index 1e65f940d..3f7c60e52 100644 --- a/src/main/java/io/appium/java_client/service/local/Slf4jLogMessageContext.java +++ b/src/main/java/io/appium/java_client/service/local/Slf4jLogMessageContext.java @@ -1,5 +1,7 @@ package io.appium.java_client.service.local; +import lombok.AccessLevel; +import lombok.Getter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.event.Level; @@ -9,31 +11,23 @@ * */ public final class Slf4jLogMessageContext { - private final Logger logger; - private final Level level; - - Slf4jLogMessageContext(String loggerName, Level level) { - this.level = level; - this.logger = LoggerFactory.getLogger(loggerName); - } - /** * Returns the {@link Logger} instance associated with this context. - * + * * @return {@link Logger} instance associated with this context. - * + * */ - public Logger getLogger() { - return logger; - } - + @Getter(AccessLevel.PUBLIC) private final Logger logger; /** * Returns log {@link Level} for the log message associated with this context. - * + * * @return {@link Level} for log message associated with this context. */ - public Level getLevel() { - return level; + @Getter(AccessLevel.PUBLIC) private final Level level; + + Slf4jLogMessageContext(String loggerName, Level level) { + this.level = level; + this.logger = LoggerFactory.getLogger(loggerName); } /** From 7d7e254d3a113ceaeca2939690859ba6c73b4185 Mon Sep 17 00:00:00 2001 From: Sai Krishna Date: Thu, 1 Aug 2019 08:54:51 +0100 Subject: [PATCH 024/675] Mark Selendroid AutomationName as deprecated (#1198) --- .../pagefactory/bys/builder/AppiumByBuilder.java | 1 - .../appium/java_client/remote/AutomationName.java | 1 + .../widget/tests/android/AndroidApp.java | 14 ++++++-------- .../tests/android/AnnotatedAndroidWidget.java | 1 - .../widget/tests/android/DefaultAndroidWidget.java | 1 - 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java index a401ac456..827a8ecbe 100644 --- a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java +++ b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java @@ -17,7 +17,6 @@ package io.appium.java_client.pagefactory.bys.builder; import static io.appium.java_client.remote.AutomationName.IOS_XCUI_TEST; -import static io.appium.java_client.remote.AutomationName.SELENDROID; import static io.appium.java_client.remote.MobilePlatform.ANDROID; import static io.appium.java_client.remote.MobilePlatform.IOS; import static io.appium.java_client.remote.MobilePlatform.WINDOWS; diff --git a/src/main/java/io/appium/java_client/remote/AutomationName.java b/src/main/java/io/appium/java_client/remote/AutomationName.java index 828ee9085..ce85512c1 100644 --- a/src/main/java/io/appium/java_client/remote/AutomationName.java +++ b/src/main/java/io/appium/java_client/remote/AutomationName.java @@ -19,6 +19,7 @@ public interface AutomationName { String APPIUM = "Appium"; + @Deprecated String SELENDROID = "Selendroid"; String IOS_XCUI_TEST = "XCuiTest"; String ANDROID_UIAUTOMATOR2 = "UIAutomator2"; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidApp.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidApp.java index bc9897e54..e33832265 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidApp.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidApp.java @@ -8,10 +8,8 @@ public class AndroidApp implements ExtendedApp { public static String ANDROID_DEFAULT_WIDGET_LOCATOR = "SOME_ANDROID_DEFAULT_LOCATOR"; - public static String ANDROID_SELENDROID_WIDGET_LOCATOR = "SOME_SELENDROID_DEFAULT_LOCATOR"; public static String ANDROID_EXTERNALLY_DEFINED_WIDGET_LOCATOR = "SOME_ANDROID_EXTERNALLY_DEFINED_LOCATOR"; - public static String SELENDROID_EXTERNALLY_DEFINED_WIDGET_LOCATOR = "SOME_SELENDROID_EXTERNALLY_DEFINED_LOCATOR"; @AndroidFindBy(uiAutomator = "SOME_ANDROID_DEFAULT_LOCATOR") private DefaultAndroidWidget singleAndroidWidget; @@ -20,35 +18,35 @@ public class AndroidApp implements ExtendedApp { private List multipleAndroidWidgets; /** - * This class is annotated by {@link AndroidFindBy} and @{@link SelendroidFindBy}. + * This class is annotated by {@link AndroidFindBy} * This field was added to check that locator is created correctly according to current platform * and current automation. */ private AnnotatedAndroidWidget singleAnnotatedAndroidWidget; /** - * This class is annotated by {@link AndroidFindBy} and @{@link SelendroidFindBy}. + * This class is annotated by {@link AndroidFindBy} * This field was added to check that locator is created correctly according to current platform * and current automation. */ private List multipleAnnotatedAndroidWidgets; /** - * This class is not annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}. + * This class is not annotated by {@link AndroidFindBy} * But the superclass is annotated by these annotations. This field was added to check that locator is * created correctly according to current platform and current automation. */ private ExtendedAndroidWidget singleExtendedAndroidWidget; /** - * This class is not annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}. + * This class is not annotated by {@link AndroidFindBy} * But the superclass is annotated by these annotations. This field was added to check that locator is * created correctly according to current platform and current automation. */ private List multipleExtendedAndroidWidgets; /** - * The superclass is annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}. + * The superclass is annotated by {@link AndroidFindBy} * However there is the field which is annotated by this annotations. * This field was added to check that locator is * created correctly according to current platform and current automation and @@ -58,7 +56,7 @@ public class AndroidApp implements ExtendedApp { private ExtendedAndroidWidget singleOverriddenAndroidWidget; /** - * The superclass is annotated by {@link AndroidFindBy} and {@link SelendroidFindBy}. + * The superclass is annotated by {@link AndroidFindBy} * However there is the field which is annotated by this annotations. * This field was added to check that locator is * created correctly according to current platform and current automation and diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AnnotatedAndroidWidget.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AnnotatedAndroidWidget.java index e58e14a2b..b64b3361d 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AnnotatedAndroidWidget.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AnnotatedAndroidWidget.java @@ -6,7 +6,6 @@ @AndroidFindBy(uiAutomator = "SOME_ROOT_LOCATOR") public class AnnotatedAndroidWidget extends DefaultAndroidWidget { public static String ANDROID_ROOT_WIDGET_LOCATOR = "SOME_ROOT_LOCATOR"; - public static String SELENDROID_ROOT_WIDGET_LOCATOR = "SELENDROID_SOME_ROOT_LOCATOR"; protected AnnotatedAndroidWidget(WebElement element) { super(element); diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/DefaultAndroidWidget.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/DefaultAndroidWidget.java index 59e9dc253..1fcd02771 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/DefaultAndroidWidget.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/DefaultAndroidWidget.java @@ -9,7 +9,6 @@ public class DefaultAndroidWidget extends DefaultStubWidget { public static String ANDROID_SUB_WIDGET_LOCATOR = "SOME_SUB_LOCATOR"; - public static String SELENDROID_SUB_WIDGET_LOCATOR = "SELENDROID_SOME_SUB_LOCATOR"; @AndroidFindBy(uiAutomator = "SOME_SUB_LOCATOR") private DefaultAndroidWidget singleWidget; From 960caf43c0c332b3cbcb2cffd7947d89c122a114 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 11 Aug 2019 06:33:36 +0530 Subject: [PATCH 025/675] Fix builds in jitpack.io (#1203) --- jitpack.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jitpack.yml b/jitpack.yml index fe6c1ec3c..c4432703f 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,4 +1,4 @@ jdk: - openjdk8 install: - - ./gradlew clean install -x test -x signMavenJavaPublication + - ./gradlew clean build publishToMavenLocal -x signMavenJavaPublication -x test -x checkstyleTest From 8e047836bb5881de4f59740fd9f58565c09f7705 Mon Sep 17 00:00:00 2001 From: Takeshi Kishi Date: Sat, 17 Aug 2019 23:08:02 +0900 Subject: [PATCH 026/675] Update javadoc of capabilities to follow latest Appium documents (#1204) * update General capabilities * update Android capabilities * update iOS capabilities * fix headlines * fix reviewed code. * edit Android appWaitActivity docs --- .../remote/AndroidMobileCapabilityType.java | 49 +++++++++++----- .../remote/IOSMobileCapabilityType.java | 56 ++++++++++++++----- .../remote/MobileCapabilityType.java | 51 +++++++++++------ 3 files changed, 114 insertions(+), 42 deletions(-) diff --git a/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java index 60acb0b77..ad1a792ec 100644 --- a/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java @@ -19,29 +19,39 @@ import org.openqa.selenium.remote.CapabilityType; /** - * The list of Android-specific capabilities. - * Read: - * https://github.com/appium/appium/blob/1.5/docs/en/writing-running-appium/caps.md#android-only + * The list of Android-specific capabilities.
+ * Read:
+ * + * https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md#android-only */ public interface AndroidMobileCapabilityType extends CapabilityType { + /** * Activity name for the Android activity you want to launch from your package. - * This often needs to be preceded by a . (e.g., .MainActivity instead of MainActivity). + * This often needs to be preceded by a {@code .} (e.g., {@code .MainActivity} + * instead of {@code MainActivity}). By default this capability is received from the package + * manifest (action: android.intent.action.MAIN , category: android.intent.category.LAUNCHER) */ String APP_ACTIVITY = "appActivity"; /** - * Java package of the Android app you want to run. + * Java package of the Android app you want to run. By default this capability is received + * from the package manifest ({@literal @}package attribute value) */ String APP_PACKAGE = "appPackage"; /** - * Activity name for the Android activity you want to wait for. + * Activity name/names, comma separated, for the Android activity you want to wait for. + * By default the value of this capability is the same as for {@code appActivity}. + * You must set it to the very first focused application activity name in case it is different + * from the one which is set as {@code appActivity} if your capability has {@code appActivity} + * and {@code appPackage}. You can also use wildcards ({@code *}). */ String APP_WAIT_ACTIVITY = "appWaitActivity"; /** * Java package of the Android app you want to wait for. + * By default the value of this capability is the same as for {@code appActivity} */ String APP_WAIT_PACKAGE = "appWaitPackage"; @@ -63,7 +73,10 @@ public interface AndroidMobileCapabilityType extends CapabilityType { /** * (Chrome and webview only) Enable Chromedriver's performance logging (default false). + * + * @deprecated move to {@link MobileCapabilityType#ENABLE_PERFORMANCE_LOGGING} */ + @Deprecated String ENABLE_PERFORMANCE_LOGGING = "enablePerformanceLogging"; /** @@ -164,8 +177,9 @@ public interface AndroidMobileCapabilityType extends CapabilityType { String INTENT_FLAGS = "intentFlags"; /** - * Additional intent arguments that will be used to start activity. See Intent arguments: - * http://developer.android.com/reference/android/content/Intent.html + * Additional intent arguments that will be used to start activity. See + * + * Intent arguments. */ String OPTIONAL_INTENT_ARGUMENTS = "optionalIntentArguments"; @@ -214,8 +228,9 @@ public interface AndroidMobileCapabilityType extends CapabilityType { /** * Allows passing chromeOptions capability for ChromeDriver. - * For more information see chromeOptions: - * https://sites.google.com/a/chromium.org/chromedriver/capabilities + * For more information see + * + * chromeOptions. */ String CHROME_OPTIONS = "chromeOptions"; @@ -244,13 +259,21 @@ public interface AndroidMobileCapabilityType extends CapabilityType { String AUTO_GRANT_PERMISSIONS = "autoGrantPermissions"; /** - * Add androidNaturalOrientation capability to allow for correct handling of - * orientation on landscape-oriented devices. + * Allow for correct handling of orientation on landscape-oriented devices. + * Set to {@code true} to basically flip the meaning of {@code PORTRAIT} and {@code LANDSCAPE}. + * Defaults to {@code false}. */ String ANDROID_NATURAL_ORIENTATION = "androidNaturalOrientation"; /** - * The port number, which being used by UIAutomator2. + * {@code systemPort} used to connect to + * appium-uiautomator2-server or + * appium-espresso-driver. + * The default is {@code 8200} in general and selects one port from {@code 8200} to {@code 8299} + * for appium-uiautomator2-server, it is {@code 8300} from {@code 8300} to {@code 8399} for + * appium-espresso-driver. When you run tests in parallel, you must adjust the port to avoid conflicts. Read + * + * Parallel Testing Setup Guide for more details. */ String SYSTEM_PORT = "systemPort"; } diff --git a/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java index 2ddae1694..4fcf8a444 100644 --- a/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java @@ -19,9 +19,14 @@ import org.openqa.selenium.remote.CapabilityType; /** - * The list of iOS-specific capabilities. - * Read: - * https://github.com/appium/appium/blob/1.5/docs/en/writing-running-appium/caps.md#ios-only + * The list of iOS-specific capabilities.
+ * Read:
+ * + * https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md#ios-only + *
+ * and
+ * + * https://github.com/appium/appium-xcuitest-driver#desired-capabilities */ public interface IOSMobileCapabilityType extends CapabilityType { @@ -78,7 +83,7 @@ public interface IOSMobileCapabilityType extends CapabilityType { String NATIVE_INSTRUMENTS_LIB = "nativeInstrumentsLib"; /** - * (Sim-only) Enable "real", non-javascript-based web taps in Safari. + * Enable "real", non-javascript-based web taps in Safari. * Default: false. * Warning: depending on viewport size/ratio this might not accurately tap an element. */ @@ -164,7 +169,7 @@ public interface IOSMobileCapabilityType extends CapabilityType { String APP_NAME = "appName"; /** - * Capability to pre-authorize a specific SSL cert in the iOS trust store. + * (Sim only) Add an SSL certificate to IOS Simulator. */ String CUSTOM_SSL_CERT = "customSSLCert"; @@ -175,8 +180,11 @@ public interface IOSMobileCapabilityType extends CapabilityType { String TAP_WITH_SHORT_PRESS_DURATION = "tapWithShortPressDuration"; /** - * The capability to direct Appium to set the simulator scale. - * The XCUITest specific capability. + * Simulator scale factor. + * This is useful to have if the default resolution of simulated device is + * greater than the actual display resolution. So you can scale the simulator + * to see the whole device screen without scrolling. + * This capability only works below Xcode9. */ String SCALE_FACTOR = "scaleFactor"; @@ -229,7 +237,10 @@ public interface IOSMobileCapabilityType extends CapabilityType { * creating tons of unnecessary screenshots and logs, * which are impossible to shutdown using programming * interfaces provided by Apple + * + * @deprecated This capability was deleted at Appium 1.14.0 */ + @Deprecated String PREVENT_WDAATTACHMENTS = "preventWDAAttachments"; /** @@ -248,18 +259,28 @@ public interface IOSMobileCapabilityType extends CapabilityType { String KEYCHAIN_PATH = "keychainPath"; /** - * Forces uninstall of any existing WebDriverAgent app on device. - * This can provide stability in some situations. Defaults to false. + * If {@code true}, forces uninstall of any existing WebDriverAgent app on device. + * Set it to {@code true} if you want to apply different startup options for WebDriverAgent for each session. + * Although, it is only guaranteed to work stable on Simulator. Real devices require WebDriverAgent + * client to run for as long as possible without reinstall/restart to avoid issues like + * + * https://github.com/facebook/WebDriverAgent/issues/507. + * The {@code false} value (the default behaviour since driver version 2.35.0) will try to detect currently + * running WDA listener executed by previous testing session(s) and reuse it if possible, which is + * highly recommended for real device testing and to speed up suites of multiple tests in general. + * A new WDA session will be triggered at the default URL (http://localhost:8100) if WDA is not + * listening and {@code webDriverAgentUrl} capability is not set. The negative/unset value of {@code useNewWDA} + * capability has no effect prior to xcuitest driver version 2.35.0. */ String USE_NEW_WDA = "useNewWDA"; /** - * Time, in ms, to wait for WebDriverAgewnt to be pingable. Defaults to 60000ms. + * Time, in ms, to wait for WebDriverAgent to be pingable. Defaults to 60000ms. */ String WDA_LAUNCH_TIMEOUT = "wdaLaunchTimeout"; /** - * Timeout, in ms, for waiting for a resonse from WebDriverAgent. Defaults to 240000ms. + * Timeout, in ms, for waiting for a response from WebDriverAgent. Defaults to 240000ms. */ String WDA_CONNECTION_TIMEOUT = "wdaConnectionTimeout"; @@ -273,7 +294,7 @@ public interface IOSMobileCapabilityType extends CapabilityType { /** * String representing a signing certificate. * Must be used in conjunction with xcodeOrgId. - * This is usually just iPhone Developer. + * This is usually just iPhone Developer, so the default (if not included) is iPhone Developer */ String XCODE_SIGNING_ID = "xcodeSigningId"; @@ -288,13 +309,22 @@ public interface IOSMobileCapabilityType extends CapabilityType { * Whether to perform reset on test session finish (false) or not (true). * Keeping this variable set to true and Simulator running * (the default behaviour since version 1.6.4) may significantly shorten the - * duratiuon of test session initialization. + * duration of test session initialization. * Defaults to true. */ String RESET_ON_SESSION_START_ONLY = "resetOnSessionStartOnly"; /** * Custom timeout(s) in milliseconds for WDA backend commands execution. + * This might be useful if WDA backend freezes unexpectedly or requires + * too much time to fail and blocks automated test execution. + * The value is expected to be of type string and can either contain + * max milliseconds to wait for each WDA command to be executed before + * terminating the session forcefully or a valid JSON string, + * where keys are internal Appium command names (you can find these in logs, + * look for "Executing command 'command_name'" records) and values are + * timeouts in milliseconds. You can also set the 'default' key to assign + * the timeout for all other commands not explicitly enumerated as JSON keys. */ String COMMAND_TIMEOUTS = "commandTimeouts"; diff --git a/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java index 46a873c23..1ce83cf0b 100644 --- a/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java @@ -19,10 +19,10 @@ import org.openqa.selenium.remote.CapabilityType; /** - * The list of common capabilities. - * Read: - * https://github.com/appium/appium/blob/1.5/docs/en/ - * writing-running-appium/caps.md#appium-server-capabilities + * The list of common capabilities.
+ * Read:
+ * + * https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md#general-capabilities */ public interface MobileCapabilityType extends CapabilityType { @@ -48,11 +48,15 @@ public interface MobileCapabilityType extends CapabilityType { String NEW_COMMAND_TIMEOUT = "newCommandTimeout"; /** - * The absolute local path or remote http URL to an .ipa or .apk file, - * or a .zip containing one of these. Appium will attempt to install this app - * binary on the appropriate device first. Note that this capability is not required for - * Android if you specify appPackage and appActivity capabilities (see below). - * Incompatible with browserName. + * The absolute local path or remote http URL to a {@code .ipa} file (IOS), + * {@code .app} folder (IOS Simulator), {@code .apk} file (Android) or {@code .apks} file (Android App Bundle), + * or a {@code .zip} file containing one of these (for .app, the .app folder must be the root of the zip file). + * Appium will attempt to install this app binary on the appropriate device first. + * Note that this capability is not required for Android if you specify {@code appPackage} + * and {@code appActivity} capabilities (see below). Incompatible with {@code browserName}. See + * + * here + * about {@code .apks} file. */ String APP = "app"; @@ -67,12 +71,13 @@ public interface MobileCapabilityType extends CapabilityType { String APPIUM_VERSION = "appiumVersion"; /** - * (Sim/Emu-only) Language to set for the simulator / emulator. + * Language to set for iOS (XCUITest driver only) and Android. */ String LANGUAGE = "language"; /** - * (Sim/Emu-only) Locale to set for the simulator / emulator. + * Locale to set for iOS (XCUITest driver only) and Android. + * {@code fr_CA} format for iOS. {@code CA} format (country name abbreviation) for Android */ String LOCALE = "locale"; @@ -87,14 +92,18 @@ public interface MobileCapabilityType extends CapabilityType { String AUTO_WEBVIEW = "autoWebview"; /** - * Don't reset app state before this session. Default false. + * Don't reset app state before this session. See + * + * here + * for more detail. */ String NO_RESET = "noReset"; /** - * (iOS) Delete the entire simulator folder. - * (Android) Reset app state by uninstalling app instead of clearing app data. - * On Android, this will also remove the app after the session is complete. Default false. + * Perform a complete reset. See + * + * here + * for more detail. */ String FULL_RESET = "fullReset"; @@ -106,7 +115,11 @@ public interface MobileCapabilityType extends CapabilityType { /** * Enable or disable the reporting of the timings for various Appium-internal events - * (e.g., the start and end of each command, etc.). Defaults to false. + * (e.g., the start and end of each command, etc.). Defaults to {@code false}. + * To enable, use {@code true}. The timings are then reported as {@code events} property on response + * to querying the current session. See the + * + * event timing docs for the the structure of this response. */ String EVENT_TIMINGS = "eventTimings"; @@ -115,4 +128,10 @@ public interface MobileCapabilityType extends CapabilityType { * If {@code false} then it is switched to W3C mode. */ String FORCE_MJSONWP = "forceMjsonwp"; + + /** + * (Web and webview only) Enable ChromeDriver's (on Android) + * or Safari's (on iOS) performance logging (default {@code false}). + */ + String ENABLE_PERFORMANCE_LOGGING = "enablePerformanceLogging"; } From f4cdaf7821d368e9eefbdffefdc9d7fd03a7ae65 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Mon, 19 Aug 2019 23:39:39 +0530 Subject: [PATCH 027/675] Fix #1208 (#1209) This reverts commit 6d0de818812878009e15fc055136933b14030020. --- gradle.properties | 2 +- .../io/appium/java_client/remote/AppiumCommandExecutor.java | 2 +- .../io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5a9863788..9bd535700 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ signing.secretKeyRingFile=PathToYourKeyRingFile ossrhUsername=your-jira-id ossrhPassword=your-jira-password -selenium.version=4.0.0-alpha-1 +selenium.version=3.141.59 diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index 707680b4f..3f094ff53 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -44,10 +44,10 @@ import org.openqa.selenium.remote.ProtocolHandshake; import org.openqa.selenium.remote.Response; import org.openqa.selenium.remote.ResponseCodec; -import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; import org.openqa.selenium.remote.http.HttpClient; import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; +import org.openqa.selenium.remote.http.W3CHttpCommandCodec; import org.openqa.selenium.remote.service.DriverService; import java.io.BufferedInputStream; diff --git a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java index 0fe0ace05..aec7ebd75 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java +++ b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java @@ -32,7 +32,7 @@ import org.openqa.selenium.interactions.KeyInput; import org.openqa.selenium.interactions.Sequence; -import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; +import org.openqa.selenium.remote.http.W3CHttpCommandCodec; import java.util.Collection; import java.util.Map; From 7239a9d44cd088b6c457c93ac8a90a4cf797dd17 Mon Sep 17 00:00:00 2001 From: Wasiq Bhamla Date: Wed, 21 Aug 2019 01:51:26 +0530 Subject: [PATCH 028/675] Upgraded Selenium version to alpha 2. (#1210) * Upgraded Selenium version to alpha 2. * Updated for changes for Selenium alpha 2. * Updated for compilation errors. --- gradle.properties | 2 +- .../appium/java_client/remote/AppiumCommandExecutor.java | 2 +- .../java_client/remote/AppiumW3CHttpCommandCodec.java | 2 +- .../java_client/android/OpenNotificationsTest.java | 3 ++- .../io/appium/java_client/android/UIAutomator2Test.java | 9 +++++---- .../element/generation/ios/IOSElementGenerationTest.java | 5 +++-- .../java/io/appium/java_client/ios/IOSAlertTest.java | 3 ++- .../java/io/appium/java_client/ios/IOSDriverTest.java | 9 +++++---- .../java/io/appium/java_client/ios/IOSElementTest.java | 3 ++- .../java_client/ios/IOSNativeWebTapSettingTest.java | 7 ++++--- .../java/io/appium/java_client/ios/IOSTouchTest.java | 4 ++-- .../java/io/appium/java_client/ios/IOSWebViewTest.java | 7 +++++-- .../java_client/pagefactory_tests/XCUITModeTest.java | 3 ++- 13 files changed, 35 insertions(+), 24 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9bd535700..63b13d41e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ signing.secretKeyRingFile=PathToYourKeyRingFile ossrhUsername=your-jira-id ossrhPassword=your-jira-password -selenium.version=3.141.59 +selenium.version=4.0.0-alpha-2 \ No newline at end of file diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index 3f094ff53..707680b4f 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -44,10 +44,10 @@ import org.openqa.selenium.remote.ProtocolHandshake; import org.openqa.selenium.remote.Response; import org.openqa.selenium.remote.ResponseCodec; +import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; import org.openqa.selenium.remote.http.HttpClient; import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; -import org.openqa.selenium.remote.http.W3CHttpCommandCodec; import org.openqa.selenium.remote.service.DriverService; import java.io.BufferedInputStream; diff --git a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java index aec7ebd75..0fe0ace05 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java +++ b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java @@ -32,7 +32,7 @@ import org.openqa.selenium.interactions.KeyInput; import org.openqa.selenium.interactions.Sequence; -import org.openqa.selenium.remote.http.W3CHttpCommandCodec; +import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; import java.util.Collection; import java.util.Map; diff --git a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java index 7806ecc14..d6af69d05 100644 --- a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java +++ b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java @@ -1,5 +1,6 @@ package io.appium.java_client.android; +import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertNotEquals; import static org.openqa.selenium.By.id; @@ -14,7 +15,7 @@ public class OpenNotificationsTest extends BaseAndroidTest { public void openNotification() { driver.closeApp(); driver.openNotifications(); - WebDriverWait wait = new WebDriverWait(driver, 20); + WebDriverWait wait = new WebDriverWait(driver, ofSeconds(20)); assertNotEquals(0, wait.until(input -> { List result = input .findElements(id("com.android.systemui:id/settings_button")); diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java index 19df3618a..bca878dda 100644 --- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java +++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java @@ -1,5 +1,6 @@ package io.appium.java_client.android; +import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -23,7 +24,7 @@ public void afterMethod() { @Test public void testLandscapeRightRotation() { - new WebDriverWait(driver, 20).until(ExpectedConditions + new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions .elementToBeClickable(driver.findElementById("android:id/content") .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90); @@ -33,7 +34,7 @@ public void testLandscapeRightRotation() { @Test public void testLandscapeLeftRotation() { - new WebDriverWait(driver, 20).until(ExpectedConditions + new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions .elementToBeClickable(driver.findElementById("android:id/content") .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270); @@ -43,7 +44,7 @@ public void testLandscapeLeftRotation() { @Test public void testPortraitUpsideDown() { - new WebDriverWait(driver, 20).until(ExpectedConditions + new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions .elementToBeClickable(driver.findElementById("android:id/content") .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180); @@ -56,7 +57,7 @@ public void testPortraitUpsideDown() { */ @Ignore public void testToastMSGIsDisplayed() { - final WebDriverWait wait = new WebDriverWait(driver, 30); + final WebDriverWait wait = new WebDriverWait(driver, ofSeconds(30)); Activity activity = new Activity("io.appium.android.apis", ".view.PopupMenu1"); driver.startActivity(activity); diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java index 0b7572be3..7ed8832e5 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -1,6 +1,7 @@ package io.appium.java_client.appium.element.generation.ios; import static io.appium.java_client.MobileBy.AccessibilityId; +import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertTrue; import static org.openqa.selenium.By.id; import static org.openqa.selenium.By.name; @@ -84,11 +85,11 @@ public void whenIOSHybridAppIsLaunched() { Capabilities caps = commonAppCapabilitiesSupplier.get(); return caps.merge(appFileSupplierFunction.apply(webViewApp).get()); }, (by, aClass) -> { - new WebDriverWait(driver, 30) + new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions.presenceOfElementLocated(id("login"))) .click(); driver.findElementByAccessibilityId("webView").click(); - new WebDriverWait(driver, 30) + new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions .presenceOfElementLocated(AccessibilityId("Webview"))); try { diff --git a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java index 06df51bd7..7c46a3c4d 100644 --- a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java @@ -16,6 +16,7 @@ package io.appium.java_client.ios; +import static java.time.Duration.ofSeconds; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertTrue; import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; @@ -32,7 +33,7 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class IOSAlertTest extends AppIOSTest { - private WebDriverWait waiting = new WebDriverWait(driver, 10000); + private WebDriverWait waiting = new WebDriverWait(driver, ofSeconds(10000)); private static final String iOSAutomationText = "show alert"; @Test public void acceptAlertTest() { diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 995ac4c58..69056af48 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -16,6 +16,7 @@ package io.appium.java_client.ios; +import static java.time.Duration.ofSeconds; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -56,7 +57,7 @@ public void getDeviceTimeTest() { } @Test public void hideKeyboardWithParametersTest() { - new WebDriverWait(driver, 30) + new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions.presenceOfElementLocated(By.id("IntegerA"))) .click(); driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done"); @@ -102,7 +103,7 @@ public void getDeviceTimeTest() { @Test public void putAppIntoBackgroundAndRestoreTest() { final long msStarted = System.currentTimeMillis(); - driver.runAppInBackground(Duration.ofSeconds(4)); + driver.runAppInBackground(ofSeconds(4)); assertThat(System.currentTimeMillis() - msStarted, greaterThan(3000L)); } @@ -119,7 +120,7 @@ public void getDeviceTimeTest() { } assertThat(driver.queryAppState(BUNDLE_ID), equalTo(ApplicationState.RUNNING_IN_FOREGROUND)); Thread.sleep(500); - driver.runAppInBackground(Duration.ofSeconds(-1)); + driver.runAppInBackground(ofSeconds(-1)); assertThat(driver.queryAppState(BUNDLE_ID), lessThan(ApplicationState.RUNNING_IN_FOREGROUND)); Thread.sleep(500); driver.activateApp(BUNDLE_ID); @@ -128,7 +129,7 @@ public void getDeviceTimeTest() { @Test public void putAIntoBackgroundWithoutRestoreTest() { assertThat(driver.findElementsById("IntegerA"), is(not(empty()))); - driver.runAppInBackground(Duration.ofSeconds(-1)); + driver.runAppInBackground(ofSeconds(-1)); assertThat(driver.findElementsById("IntegerA"), is(empty())); driver.launchApp(); } diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/test/java/io/appium/java_client/ios/IOSElementTest.java index 4389d1888..18bbf0d69 100644 --- a/src/test/java/io/appium/java_client/ios/IOSElementTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSElementTest.java @@ -1,5 +1,6 @@ package io.appium.java_client.ios; +import static java.time.Duration.ofSeconds; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; @@ -25,7 +26,7 @@ public void findByAccessibilityIdTest() { @Ignore @Test public void setValueTest() { - WebDriverWait wait = new WebDriverWait(driver, 20); + WebDriverWait wait = new WebDriverWait(driver, ofSeconds(20)); IOSElement slider = wait.until( driver1 -> driver1.findElement(By.className("XCUIElementTypeSlider"))); 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 cc23af210..25f287bc5 100644 --- a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java @@ -1,5 +1,6 @@ package io.appium.java_client.ios; +import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -16,17 +17,17 @@ public class IOSNativeWebTapSettingTest extends BaseSafariTest { driver.nativeWebTap(true); WebElement el = driver.findElementById("i am a link"); el.click(); - assertTrue(new WebDriverWait(driver, 30) + assertTrue(new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs"))); driver.navigate().back(); // now do a click with it turned off and assert the same behavior - assertTrue(new WebDriverWait(driver, 30) + assertTrue(new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions.titleIs("I am a page title - Sauce Labs"))); driver.nativeWebTap(false); el = driver.findElementById("i am a link"); el.click(); - assertTrue(new WebDriverWait(driver, 30) + assertTrue(new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs"))); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java index ea2f83d9d..8b6d34b04 100644 --- a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java @@ -58,7 +58,7 @@ public void touchWithPressureTest() { } @Test public void swipeTest() { - WebDriverWait webDriverWait = new WebDriverWait(driver, 30); + WebDriverWait webDriverWait = new WebDriverWait(driver, ofSeconds(30)); IOSElement slider = webDriverWait.until(driver1 -> driver.findElementByClassName("XCUIElementTypeSlider")); Dimension size = slider.getSize(); @@ -82,7 +82,7 @@ public void touchWithPressureTest() { new MultiTouchAction(driver).add(tap1).add(tap2).perform(); - WebDriverWait waiting = new WebDriverWait(driver, 10000); + WebDriverWait waiting = new WebDriverWait(driver, ofSeconds(10000)); assertNotNull(waiting.until(alertIsPresent())); driver.switchTo().alert().accept(); } diff --git a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java index 7c8f380c3..d12d5aa16 100644 --- a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java @@ -1,5 +1,6 @@ package io.appium.java_client.ios; +import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertTrue; import io.appium.java_client.MobileBy; @@ -9,14 +10,16 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; +import java.time.Duration; + public class IOSWebViewTest extends BaseIOSWebViewTest { @Test public void webViewPageTestCase() throws InterruptedException { - new WebDriverWait(driver, 30) + new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions.presenceOfElementLocated(By.id("login"))) .click(); driver.findElementByAccessibilityId("webView").click(); - new WebDriverWait(driver, 30) + new WebDriverWait(driver, ofSeconds(30)) .until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("Webview"))); findAndSwitchToWebView(); WebElement el = driver.findElementByPartialLinkText("login"); diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java index c54bf9129..cd683709b 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java @@ -19,6 +19,7 @@ import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE; import static io.appium.java_client.pagefactory.LocatorGroupStrategy.CHAIN; +import static java.time.Duration.ofSeconds; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -47,7 +48,7 @@ public class XCUITModeTest extends AppIOSTest { private boolean populated = false; - private WebDriverWait waiting = new WebDriverWait(driver, 10000); + private WebDriverWait waiting = new WebDriverWait(driver, ofSeconds(10000)); @HowToUseLocators(iOSXCUITAutomation = ALL_POSSIBLE) @iOSXCUITFindBy(iOSNsPredicate = "label contains 'Compute'") From 1e80399ec649606d4ebf8330250cc4782168704b Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 27 Aug 2019 13:38:44 +0200 Subject: [PATCH 029/675] fix: Avoid using getSession call for capability values retrieval (#1216) --- .../io/appium/java_client/AppiumDriver.java | 19 +++++-- .../internal/CapabilityHelpers.java | 52 +++++++++++++++++++ .../java_client/internal/ElementMap.java | 4 +- .../JsonToMobileElementConverter.java | 12 ++--- .../pagefactory/AppiumFieldDecorator.java | 49 ++++++++--------- .../utils/WebDriverUnpackUtility.java | 4 +- .../remote/NewAppiumSessionPayload.java | 2 +- .../ios/IOSNativeWebTapSettingTest.java | 1 + .../widget/tests/AbstractStubWebDriver.java | 16 +++++- .../widget/tests/ExtendedWidgetTest.java | 2 +- .../tests/android/AndroidWidgetTest.java | 2 +- .../widget/tests/ios/XCUITWidgetTest.java | 2 +- .../tests/windows/WindowsWidgetTest.java | 2 +- .../service/local/StartingAppLocallyTest.java | 2 + 14 files changed, 122 insertions(+), 47 deletions(-) create mode 100644 src/main/java/io/appium/java_client/internal/CapabilityHelpers.java diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index c95224da0..c0c1aca0e 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -19,9 +19,11 @@ import static com.google.common.base.Preconditions.checkNotNull; import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME; import static org.apache.commons.lang3.StringUtils.containsIgnoreCase; +import static org.apache.commons.lang3.StringUtils.isBlank; import com.google.common.collect.ImmutableMap; +import io.appium.java_client.internal.CapabilityHelpers; import io.appium.java_client.internal.JsonToMobileElementConverter; import io.appium.java_client.remote.AppiumCommandExecutor; import io.appium.java_client.remote.MobileCapabilityType; @@ -88,7 +90,7 @@ public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) { locationContext = new RemoteLocationContext(executeMethod); super.setErrorHandler(errorHandler); this.remoteAddress = executor.getAddressOfRemoteServer(); - this.setElementConverter(new JsonToMobileElementConverter(this, this)); + this.setElementConverter(new JsonToMobileElementConverter(this)); } public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { @@ -314,8 +316,19 @@ public URL getRemoteAddress() { @Override public boolean isBrowser() { - return super.isBrowser() - && !containsIgnoreCase(getContext(), "NATIVE_APP"); + String browserName = CapabilityHelpers.getCapability(getCapabilities(), "browserName", String.class); + if (!isBlank(browserName)) { + try { + return (boolean) executeScript("return !!window.navigator;"); + } catch (WebDriverException ign) { + // ignore + } + } + try { + return !containsIgnoreCase(getContext(), "NATIVE_APP"); + } catch (WebDriverException e) { + return false; + } } @Override diff --git a/src/main/java/io/appium/java_client/internal/CapabilityHelpers.java b/src/main/java/io/appium/java_client/internal/CapabilityHelpers.java new file mode 100644 index 000000000..0cb9ec96c --- /dev/null +++ b/src/main/java/io/appium/java_client/internal/CapabilityHelpers.java @@ -0,0 +1,52 @@ +/* + * 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.internal; + +import org.openqa.selenium.Capabilities; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +public class CapabilityHelpers { + public static final String APPIUM_PREFIX = "appium:"; + + /** + * Helper that is used for capability values retrieval. + * Supports both prefixed W3C and "classic" capability names. + * + * @param caps driver caps object + * @param name capability name + * @param expectedType the expected capability type + * @return The retrieved capability value or null if the cap either not present has an unexpected type + */ + @Nullable + public static T getCapability(Capabilities caps, String name, Class expectedType) { + List possibleNames = new ArrayList<>(); + possibleNames.add(name); + if (!name.startsWith(APPIUM_PREFIX)) { + possibleNames.add(APPIUM_PREFIX + name); + } + for (String capName : possibleNames) { + if (caps.getCapability(capName) != null + && expectedType.isAssignableFrom(caps.getCapability(capName).getClass())) { + return expectedType.cast(caps.getCapability(capName)); + } + } + return null; + } +} diff --git a/src/main/java/io/appium/java_client/internal/ElementMap.java b/src/main/java/io/appium/java_client/internal/ElementMap.java index 44c852e77..5522f7cb4 100644 --- a/src/main/java/io/appium/java_client/internal/ElementMap.java +++ b/src/main/java/io/appium/java_client/internal/ElementMap.java @@ -50,12 +50,10 @@ public enum ElementMap { mobileElementMap = builder.build(); } - - private final String platformOrAutomation; private final Class elementClass; - private ElementMap(String platformOrAutomation, Class elementClass) { + ElementMap(String platformOrAutomation, Class elementClass) { this.platformOrAutomation = platformOrAutomation; this.elementClass = elementClass; } diff --git a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java index d78b90c7d..22cce7275 100644 --- a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java +++ b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java @@ -18,7 +18,7 @@ import static io.appium.java_client.internal.ElementMap.getElementClass; -import io.appium.java_client.HasSessionDetails; +import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebElement; @@ -41,20 +41,20 @@ public class JsonToMobileElementConverter extends JsonToWebElementConverter { * Creates a new instance based on {@code driver} and object with session details. * * @param driver an instance of {@link RemoteWebDriver} subclass - * @param hasSessionDetails object that has session details */ - public JsonToMobileElementConverter(RemoteWebDriver driver, HasSessionDetails hasSessionDetails) { + public JsonToMobileElementConverter(RemoteWebDriver driver) { super(driver); this.driver = driver; - this.platform = hasSessionDetails.getPlatformName(); - this.automation = hasSessionDetails.getAutomationName(); + Capabilities caps = driver.getCapabilities(); + this.platform = CapabilityHelpers.getCapability(caps, "platformName", String.class); + this.automation = CapabilityHelpers.getCapability(caps, "automationName", String.class); } @Override public Object apply(Object result) { Object toBeReturned = result; if (toBeReturned instanceof RemoteWebElement) { - toBeReturned = newRemoteWebElement(); + toBeReturned = newRemoteWebElement(); ((RemoteWebElement) toBeReturned).setId(((RemoteWebElement) result).getId()); } diff --git a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java index febee93d6..1e651f00b 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java +++ b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java @@ -20,20 +20,22 @@ import static io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy; import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility.unpackWebDriverFromSearchContext; import static java.time.Duration.ofSeconds; -import static java.util.Optional.ofNullable; import com.google.common.collect.ImmutableList; -import io.appium.java_client.HasSessionDetails; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.internal.CapabilityHelpers; import io.appium.java_client.ios.IOSElement; import io.appium.java_client.pagefactory.bys.ContentType; import io.appium.java_client.pagefactory.locator.CacheableLocator; import io.appium.java_client.windows.WindowsElement; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator; import org.openqa.selenium.support.pagefactory.ElementLocator; @@ -71,30 +73,24 @@ public class AppiumFieldDecorator implements FieldDecorator { private final String automation; private final Duration duration; - /** * Creates field decorator based on {@link SearchContext} and timeout {@code duration}. * - * @param context is an instance of {@link SearchContext} - * It may be the instance of {@link WebDriver} or {@link WebElement} or - * {@link Widget} or some other user's extension/implementation. + * @param context is an instance of {@link SearchContext} + * It may be the instance of {@link WebDriver} or {@link WebElement} or + * {@link Widget} or some other user's extension/implementation. * @param duration is a desired duration of the waiting for an element presence. */ public AppiumFieldDecorator(SearchContext context, Duration duration) { this.webDriver = unpackWebDriverFromSearchContext(context); - HasSessionDetails hasSessionDetails = ofNullable(this.webDriver).map(webDriver -> { - if (!HasSessionDetails.class.isAssignableFrom(webDriver.getClass())) { - return null; - } - return HasSessionDetails.class.cast(webDriver); - }).orElse(null); - if (hasSessionDetails == null) { - platform = null; - automation = null; + if (this.webDriver instanceof HasCapabilities) { + Capabilities caps = ((HasCapabilities) this.webDriver).getCapabilities(); + this.platform = CapabilityHelpers.getCapability(caps, "platformName", String.class); + this.automation = CapabilityHelpers.getCapability(caps, "automationName", String.class); } else { - platform = hasSessionDetails.getPlatformName(); - automation = hasSessionDetails.getAutomationName(); + this.platform = null; + this.automation = null; } this.duration = duration; @@ -115,7 +111,8 @@ protected List proxyForListLocator(ClassLoader ignored, return getEnhancedProxy(ArrayList.class, elementInterceptor); } - @Override protected boolean isDecoratableList(Field field) { + @Override + protected boolean isDecoratableList(Field field) { if (!List.class.isAssignableFrom(field.getType())) { return false; } @@ -148,7 +145,7 @@ public AppiumFieldDecorator(SearchContext context) { * Decorated page object {@code field}. * * @param ignored class loader is ignored by current implementation - * @param field is {@link Field} of page object which is supposed to be decorated. + * @param field is {@link Field} of page object which is supposed to be decorated. * @return a field value or null. */ public Object decorate(ClassLoader ignored, Field field) { @@ -197,19 +194,19 @@ private Object decorateWidget(Field field) { CacheableLocator locator = widgetLocatorFactory.createLocator(field); Map> map = - OverrideWidgetReader.read(widgetType, field, platform); + OverrideWidgetReader.read(widgetType, field, platform); if (isAlist) { return getEnhancedProxy(ArrayList.class, - new WidgetListInterceptor(locator, webDriver, map, widgetType, - duration)); + new WidgetListInterceptor(locator, webDriver, map, widgetType, + duration)); } Constructor constructor = - WidgetConstructorUtil.findConvenientConstructor(widgetType); - return getEnhancedProxy(widgetType, new Class[] {constructor.getParameterTypes()[0]}, - new Object[] {proxyForAnElement(locator)}, - new WidgetInterceptor(locator, webDriver, null, map, duration)); + WidgetConstructorUtil.findConvenientConstructor(widgetType); + return getEnhancedProxy(widgetType, new Class[]{constructor.getParameterTypes()[0]}, + new Object[]{proxyForAnElement(locator)}, + new WidgetInterceptor(locator, webDriver, null, map, duration)); } private WebElement proxyForAnElement(ElementLocator locator) { diff --git a/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java b/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java index 3fc83d3e4..b15ee6775 100644 --- a/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java +++ b/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java @@ -82,7 +82,7 @@ public static WebDriver unpackWebDriverFromSearchContext(SearchContext searchCon public static ContentType getCurrentContentType(SearchContext context) { return ofNullable(unpackWebDriverFromSearchContext(context)).map(driver -> { if (HasSessionDetails.class.isAssignableFrom(driver.getClass())) { - HasSessionDetails hasSessionDetails = HasSessionDetails.class.cast(driver); + HasSessionDetails hasSessionDetails = (HasSessionDetails) driver; if (!hasSessionDetails.isBrowser()) { return NATIVE_MOBILE_SPECIFIC; @@ -90,7 +90,7 @@ public static ContentType getCurrentContentType(SearchContext context) { } if (ContextAware.class.isAssignableFrom(driver.getClass())) { //it is desktop browser - ContextAware contextAware = ContextAware.class.cast(driver); + ContextAware contextAware = (ContextAware) driver; String currentContext = contextAware.getContext(); if (containsIgnoreCase(currentContext, NATIVE_APP_PATTERN)) { return NATIVE_MOBILE_SPECIFIC; diff --git a/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java b/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java index 9ec116337..add478a87 100644 --- a/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java +++ b/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java @@ -19,6 +19,7 @@ import static com.google.common.collect.ImmutableMap.of; import static com.google.common.collect.ImmutableMap.toImmutableMap; +import static io.appium.java_client.internal.CapabilityHelpers.APPIUM_PREFIX; import static io.appium.java_client.remote.MobileCapabilityType.FORCE_MJSONWP; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Optional.ofNullable; @@ -88,7 +89,6 @@ public class NewAppiumSessionPayload implements Closeable { .addAll(getAppiumCapabilities(AndroidMobileCapabilityType.class)) .addAll(getAppiumCapabilities(IOSMobileCapabilityType.class)) .addAll(getAppiumCapabilities(YouiEngineCapabilityType.class)).build(); - private static final String APPIUM_PREFIX = "appium:"; private static final String DESIRED_CAPABILITIES = "desiredCapabilities"; private static final String CAPABILITIES = "capabilities"; private static final String REQUIRED_CAPABILITIES = "requiredCapabilities"; 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 25f287bc5..25746f91b 100644 --- a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java @@ -11,6 +11,7 @@ public class IOSNativeWebTapSettingTest extends BaseSafariTest { @Test public void nativeWebTapSettingTest() { + assertTrue(driver.isBrowser()); driver.get("https://saucelabs.com/test/guinea-pig"); // do a click with nativeWebTap turned on, and assert we get to the right page diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/AbstractStubWebDriver.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/AbstractStubWebDriver.java index 218dea51f..7e3d5783a 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/AbstractStubWebDriver.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/AbstractStubWebDriver.java @@ -3,7 +3,6 @@ import static com.google.common.collect.ImmutableList.of; import static io.appium.java_client.remote.AutomationName.APPIUM; import static io.appium.java_client.remote.AutomationName.IOS_XCUI_TEST; -import static io.appium.java_client.remote.AutomationName.SELENDROID; import static io.appium.java_client.remote.MobilePlatform.ANDROID; import static io.appium.java_client.remote.MobilePlatform.IOS; import static io.appium.java_client.remote.MobilePlatform.WINDOWS; @@ -11,18 +10,23 @@ import io.appium.java_client.HasSessionDetails; import org.openqa.selenium.By; +import org.openqa.selenium.Capabilities; import org.openqa.selenium.Cookie; +import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.logging.Logs; +import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.Response; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; -public abstract class AbstractStubWebDriver implements WebDriver, HasSessionDetails { +public abstract class AbstractStubWebDriver implements WebDriver, HasSessionDetails, + HasCapabilities { @Override public Response execute(String driverCommand, Map parameters) { return null; @@ -104,6 +108,14 @@ public Navigation navigate() { return null; } + @Override + public Capabilities getCapabilities() { + Map caps = new HashMap<>(); + caps.put("platformName", getPlatformName()); + caps.put("automationName", getAutomationName()); + return new DesiredCapabilities(caps); + } + @Override public Options manage() { return new Options() { diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java index 2523c017b..d8d3a7b60 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java @@ -24,7 +24,7 @@ protected ExtendedWidgetTest(ExtendedApp app, WebDriver driver) { public abstract void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass(); @Test - public abstract void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations(); + public abstract void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations(); protected static void checkThatLocatorsAreCreatedCorrectly(DefaultStubWidget single, List multiple, By rootLocator, diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java index 7985e67c4..3b94b21cd 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java @@ -37,7 +37,7 @@ public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() } @Override - public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() { + public void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(), ((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(), AndroidUIAutomator(ANDROID_EXTERNALLY_DEFINED_WIDGET_LOCATOR), diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java index 6c1e4a1de..56abc937a 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java @@ -37,7 +37,7 @@ public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() } @Override - public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() { + public void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(), ((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(), iOSNsPredicateString(XCUIT_EXTERNALLY_DEFINED_WIDGET_LOCATOR), diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java index 5358b29dc..fbd9da9a6 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java @@ -37,7 +37,7 @@ public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() } @Override - public void checkCaseWhenBothWidgetFieldAndClassHaveDelaredAnnotations() { + public void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(), ((ExtendedApp) app).getExtendedWidgetsWithOverriddenLocators(), windowsAutomation(WINDOWS_EXTERNALLY_DEFINED_WIDGET_LOCATOR), diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java index ab7c1d912..1ffecff14 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java +++ b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyTest.java @@ -18,6 +18,7 @@ import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -197,6 +198,7 @@ public class StartingAppLocallyTest { assertTrue(caps.getCapability(MobileCapabilityType.PLATFORM_NAME) .toString().equalsIgnoreCase(MobilePlatform.IOS)); assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME)); + assertFalse(driver.isBrowser()); } finally { driver.quit(); } From 41b4f28623df0865980bbee3db5d53a60a91a18b Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Tue, 27 Aug 2019 21:28:11 +0530 Subject: [PATCH 030/675] update changelog and version to latest --- README.md | 11 +++++++++++ build.gradle | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5bf5e592..ba0e11a1a 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,17 @@ dependencies { ``` ## Changelog +*7.2.0* +- **[DEPENDENCY UPDATES]** + - `org.seleniumhq.selenium:selenium-java` was reverted to stable version 3.141.59. [#1209](https://github.com/appium/java-client/pull/1209) + - `org.projectlombok:lombok:1.18.8` was introduced. [#1193](https://github.com/appium/java-client/pull/1193) +- **[ENHANCEMENTS]** + - `videoFilters` property was added to IOSStartScreenRecordingOptions. [#1180](https://github.com/appium/java-client/pull/1180) +- **[IMPROVEMENTS]** + - `Selendroid` automationName was deprecated. [#1198](https://github.com/appium/java-client/pull/1198) + - JavaDocs for AndroidMobileCapabilityType and IOSMobileCapabilityType were updated. [#1204](https://github.com/appium/java-client/pull/1204) + - JitPack builds were fixed. [#1203](https://github.com/appium/java-client/pull/1203) + *7.1.0* - **[ENHANCEMENTS]** - Added an ability to get all the session details. [#1167 ](https://github.com/appium/java-client/pull/1167) diff --git a/build.gradle b/build.gradle index 04a68df9f..34437104b 100644 --- a/build.gradle +++ b/build.gradle @@ -136,7 +136,7 @@ publishing { mavenJava(MavenPublication) { groupId = 'io.appium' artifactId = 'java-client' - version = '7.1.0' + version = '7.2.0' from components.java artifact sourcesJar artifact javadocJar From 136afba9f8dcc7afae0dbb4490188ad3be48a276 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Wed, 28 Aug 2019 11:56:46 +0530 Subject: [PATCH 031/675] Github Actions (#1219) * Try Github Actions * Remove travis --- .github/workflows/gradle.yml | 17 +++++++++++++++++ .travis.yml | 28 ---------------------------- 2 files changed, 17 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/gradle.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 000000000..04241b76f --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,17 @@ +name: Appium Java Client CI + +on: [push, pull_request] + +jobs: + build: + + runs-on: macOS-latest + + steps: + - uses: actions/checkout@v1 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Gradle + run: ./gradlew clean build -x signMavenJavaPublication -x test -x checkstyleTest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 062d09d79..000000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -sudo: required - -matrix: - include: - - language: android - install: - - echo y | android update sdk -u -a -t tools - - echo y | android update sdk -u -a -t platform-tools - - echo y | android update sdk -u -a -t build-tools-25.0.2 - - echo y | android update sdk -u -a -t android-25 - - echo y | android update sdk -u -a -t extra-google-m2repository - - echo y | android update sdk -u -a -t extra-android-m2repository - os: linux - jdk: oraclejdk8 - android: - components: - - extra-android-support - - sys-img-armeabi-v7a-android-24 - script: - - ./gradlew clean build -x signMavenJavaPublication -x test -x checkstyleTest - -before_cache: - - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ -cache: - directories: - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ From 9020174c578bed5e03c24b43c2c5ba590f663201 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sat, 7 Sep 2019 13:18:04 +0200 Subject: [PATCH 032/675] fix: Fix the return type for getSystemBars call (#1230) --- .../android/HasAndroidDeviceDetails.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java b/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java index 03006185e..7984a0b43 100644 --- a/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java +++ b/src/main/java/io/appium/java_client/android/HasAndroidDeviceDetails.java @@ -10,17 +10,21 @@ public interface HasAndroidDeviceDetails extends ExecutesMethod { - /* - Retrieve the display density of the Android device. + /** + Retrieve the display density of the Android device. + + @return The density value in dpi */ default Long getDisplayDensity() { return CommandExecutionHelper.execute(this, getDisplayDensityCommand()); } - /* - Retrieve visibility and bounds information of the status and navigation bars. + /** + Retrieve visibility and bounds information of the status and navigation bars. + + @return The map where keys are bar types and values are mappings of bar properties. */ - default Map getSystemBars() { + default Map> getSystemBars() { return CommandExecutionHelper.execute(this, getSystemBarsCommand()); } From 822f0043d51ed5c15897216d6deac5821ec3913b Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sat, 7 Sep 2019 13:18:30 +0200 Subject: [PATCH 033/675] chore: Switch the implementation of backgroundApp for iOS, so it's in sync with other platforms (#1229) --- .../io/appium/java_client/InteractsWithApps.java | 9 +++++---- .../java/io/appium/java_client/ios/IOSDriver.java | 15 --------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/appium/java_client/InteractsWithApps.java b/src/main/java/io/appium/java_client/InteractsWithApps.java index f0624db4a..202360e22 100644 --- a/src/main/java/io/appium/java_client/InteractsWithApps.java +++ b/src/main/java/io/appium/java_client/InteractsWithApps.java @@ -95,13 +95,14 @@ default void resetApp() { /** * Runs the current app as a background app for the time - * requested. This is a synchronous method, it returns after the back has - * been returned to the foreground. + * requested. This is a synchronous method, it blocks while the + * application is in background. * - * @param duration The time to run App in background. Minimum time resolution is one second + * @param duration The time to run App in background. Minimum time resolution is one millisecond. + * Passing zero or a negative value will switch to Home screen and return immediately. */ default void runAppInBackground(Duration duration) { - execute(RUN_APP_IN_BACKGROUND, ImmutableMap.of("seconds", duration.getSeconds())); + execute(RUN_APP_IN_BACKGROUND, ImmutableMap.of("seconds", duration.toMillis() / 1000.0)); } /** 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 1d668c5de..229aac70b 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -16,7 +16,6 @@ package io.appium.java_client.ios; -import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND; import static io.appium.java_client.MobileCommand.prepareArguments; import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT; @@ -43,7 +42,6 @@ import org.openqa.selenium.remote.http.HttpClient; import java.net.URL; -import java.time.Duration; import java.util.Collections; import java.util.Map; @@ -169,19 +167,6 @@ public IOSDriver(Capabilities desiredCapabilities) { super(updateDefaultPlatformName(desiredCapabilities, IOS_DEFAULT_PLATFORM)); } - /** - * Runs the current app as a background app for the number of seconds - * or minimizes the app. - * - * @param duration The time to run App in background. - */ - @Override public void runAppInBackground(Duration duration) { - // timeout parameter is expected to be in milliseconds - // float values are allowed - execute(RUN_APP_IN_BACKGROUND, - prepareArguments("seconds", prepareArguments("timeout", duration.toMillis()))); - } - @Override public TargetLocator switchTo() { return new InnerTargetLocator(); } From 9fb06b159a303f9e2ed93ab4d88ddac617f079fe Mon Sep 17 00:00:00 2001 From: JamesSassano <51380750+JamesSassano@users.noreply.github.com> Date: Mon, 16 Sep 2019 01:35:19 -0400 Subject: [PATCH 034/675] fix: Page factory list element not initialized when parameterized by generic type (#1237) --- .../pagefactory/AppiumFieldDecorator.java | 8 + .../pagefactory_tests/GenericTest.java | 237 ++++++++++++++++-- 2 files changed, 224 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java index 1e651f00b..933795729 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java +++ b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java @@ -45,8 +45,10 @@ import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; import java.time.Duration; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -129,6 +131,12 @@ protected boolean isDecoratableList(Field field) { return true; } } + + if ((listType instanceof TypeVariable) + && Arrays.asList(((TypeVariable) listType).getBounds()) + .stream().anyMatch(item -> availableElementClasses.contains(item))) { + return true; + } return false; } }; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/GenericTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/GenericTest.java index 7c06ba2a5..16e83e2fe 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/GenericTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/GenericTest.java @@ -1,30 +1,156 @@ package io.appium.java_client.pagefactory_tests; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import io.appium.java_client.pagefactory.AppiumFieldDecorator; +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.remote.MobileCapabilityType; + +import org.apache.commons.lang3.NotImplementedException; import org.junit.Test; import org.openqa.selenium.By; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.HasCapabilities; +import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.support.PageFactory; +import io.appium.java_client.MobileElement; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; -import java.util.function.Supplier; public class GenericTest { - static class TempGenericPage { + /** + * The Generic types are null on an unbound page. + */ + private static void assertUnboundGenericsNull(T genericItem, + List genericItems) { + assertNull(genericItem); + assertNull(genericItems); + } + + /** + * The Generic types are not null on a page bound by a WebElement (or WebElement + * sub type). + */ + private static void assertBoundGenericsNotNull(T genericItem, + List genericItems) { + assertNotNull(genericItem); + assertNotNull(genericItems); + } + + /** + * The Element types are never null. + */ + private static void assertElementsNotNull(WebElement elementItem, + List elementItems) { + assertNotNull(elementItem); + assertNotNull(elementItems); + } + + /** + * The Object types are always null. + */ + private static void assertObjectsNull(Object objectItem, List objectItems) { + assertNull(objectItem); + assertNull(objectItems); + } + + /** + * A page with no generic types. The Object types are never initialized. + */ + static class TempNoGenericsPage { + public WebElement webElementItem; + public MobileElement mobileElementItem; + public Object objectItem; + + public List webElementItems; + public List mobileElementItems; + public List objectItems; + + public void assertInit() { + assertElementsNotNull(webElementItem, webElementItems); + assertElementsNotNull(mobileElementItem, mobileElementItems); + assertObjectsNull(objectItem, objectItems); + } + } + + /** + * A page with an unbound generic type. The generic and Object types are never + * initialized. + */ + static class TempUnboundPage { + public T genericItem; + public WebElement webElementItem; + public MobileElement mobileElementItem; + public Object objectItem; - public List items; + public List genericItems; + public List webElementItems; + public List mobileElementItems; + public List objectItems; - public List getItems() { - return items; + public void assertInit() { + assertUnboundGenericsNull(genericItem, genericItems); + assertElementsNotNull(webElementItem, webElementItems); + assertElementsNotNull(mobileElementItem, mobileElementItems); + assertObjectsNull(objectItem, objectItems); } } - static class MockWebDriver implements WebDriver { + /** + * A page with a WebElement bound generic type. The Object types are never + * initialized. + */ + static class TempWebBoundPage { + public T genericItem; + public WebElement webElementItem; + public MobileElement mobileElementItem; + public Object objectItem; + + public List genericItems; + public List webElementItems; + public List mobileElementItems; + public List objectItems; + + public void assertInit() { + assertBoundGenericsNotNull(genericItem, genericItems); + assertElementsNotNull(webElementItem, webElementItems); + assertElementsNotNull(mobileElementItem, mobileElementItems); + assertObjectsNull(objectItem, objectItems); + } + } + + /** + * A page with a MobileElement bound generic type. The Object types are never + * initialized. + */ + static class TempMobileBoundPage { + public T genericItem; + public WebElement webElementItem; + public MobileElement mobileElementItem; + public Object objectItem; + + public List genericItems; + public List webElementItems; + public List mobileElementItems; + public List objectItems; + + public void assertInit() { + assertBoundGenericsNotNull(genericItem, genericItems); + assertElementsNotNull(webElementItem, webElementItems); + assertElementsNotNull(mobileElementItem, mobileElementItems); + assertObjectsNull(objectItem, objectItems); + } + } + + static class MockWebDriver implements WebDriver, HasCapabilities { @Override public void get(String url) { @@ -42,13 +168,13 @@ public String getTitle() { } @Override - public List findElements(By by) { - return null; + public List findElements(By by) { + throw new NotImplementedException("MockWebDriver did not expect to findElements"); } @Override - public WebElement findElement(By by) { - return null; + public T findElement(By by) { + throw new NotImplementedException("MockWebDriver did not expect to findElement"); } @Override @@ -90,16 +216,85 @@ public Navigation navigate() { public Options manage() { return null; } + + @Override + public Capabilities getCapabilities() { + + final Map capabilities = new HashMap<>(); + + // These are needed to map the proxy element to a MobileElement. + capabilities.put(CapabilityType.PLATFORM_NAME, Platform.ANY.toString()); + capabilities.put(MobileCapabilityType.AUTOMATION_NAME, + AutomationName.IOS_XCUI_TEST.toString()); + + return new Capabilities() { + + @Override + public Object getCapability(String capabilityName) { + return capabilities.get(capabilityName); + } + + @Override + public Map asMap() { + return capabilities; + } + }; + } + } + + @Test + public void noGenericsTestCase() { + TempNoGenericsPage page = new TempNoGenericsPage(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); + } + + @Test + public void unBoundTestCase() { + TempUnboundPage page = new TempUnboundPage<>(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); + } + + @Test + public void unboundWebElementTestCase() { + TempUnboundPage page = new TempUnboundPage<>(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); + } + + @Test + public void webBoundUnknownElementTestCase() { + TempWebBoundPage page = new TempWebBoundPage<>(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); + } + + @Test + public void webBoundWebElementTestCase() { + TempWebBoundPage page = new TempWebBoundPage<>(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); } @Test - public void genericTestCse() { - Supplier result = () -> { - PageFactory - .initElements(new AppiumFieldDecorator(new MockWebDriver()), - new TempGenericPage<>()); - return true; - }; - assertTrue(result.get()); - } -} \ No newline at end of file + public void webBoundMobileElementTestCase() { + TempWebBoundPage page = new TempWebBoundPage<>(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); + } + + @Test + public void mobileBoundUnknownElementTestCase() { + TempMobileBoundPage page = new TempMobileBoundPage<>(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); + } + + @Test + public void mobileBoundMobileElementTestCase() { + TempMobileBoundPage page = new TempMobileBoundPage<>(); + PageFactory.initElements(new AppiumFieldDecorator(new MockWebDriver()), page); + page.assertInit(); + } +} From e19ac644699daf8cc6746f37a1bd86fb3c705e16 Mon Sep 17 00:00:00 2001 From: a-en Date: Tue, 17 Sep 2019 20:15:36 +0300 Subject: [PATCH 035/675] Update AndroidMobileCapabilityType (#1238) * missing capabilities added * minor updates * fixed checkstyle complaints * for list of caps added version since cap is available * changed description for 'autoLaunch' capability --- .../remote/AndroidMobileCapabilityType.java | 174 +++++++++++++++++- 1 file changed, 173 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java index ad1a792ec..a73e9075f 100644 --- a/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/AndroidMobileCapabilityType.java @@ -57,6 +57,7 @@ public interface AndroidMobileCapabilityType extends CapabilityType { /** * Timeout in milliseconds used to wait for the appWaitActivity to launch (default 20000). + * @since 1.6.0 */ String APP_WAIT_DURATION = "appWaitDuration"; @@ -65,12 +66,24 @@ public interface AndroidMobileCapabilityType extends CapabilityType { */ String DEVICE_READY_TIMEOUT = "deviceReadyTimeout"; + /** + * Allow to install a test package which has {@code android:testOnly="true"} in the manifest. + * {@code false} by default + */ + String ALLOW_TEST_PACKAGES = "allowTestPackages"; + /** * Fully qualified instrumentation class. Passed to -w in adb shell * am instrument -e coverage true -w. */ String ANDROID_COVERAGE = "androidCoverage"; + /** + * A broadcast action implemented by yourself which is used to dump coverage into file system. + * Passed to -a in adb shell am broadcast -a + */ + String ANDROID_COVERAGE_END_INTENT = "androidCoverageEndIntent"; + /** * (Chrome and webview only) Enable Chromedriver's performance logging (default false). * @@ -97,9 +110,17 @@ public interface AndroidMobileCapabilityType extends CapabilityType { /** * Timeout in milliseconds used to wait for an apk to install to the device. Defaults to `90000`. + * @since 1.6.0 */ String ANDROID_INSTALL_TIMEOUT = "androidInstallTimeout"; + /** + * The name of the directory on the device in which the apk will be push before install. + * Defaults to {@code /data/local/tmp} + * @since 1.6.5 + */ + String ANDROID_INSTALL_PATH = "androidInstallPath"; + /** * Name of avd to launch. */ @@ -108,12 +129,14 @@ public interface AndroidMobileCapabilityType extends CapabilityType { /** * How long to wait in milliseconds for an avd to launch and connect to * ADB (default 120000). + * @since 0.18.0 */ String AVD_LAUNCH_TIMEOUT = "avdLaunchTimeout"; /** * How long to wait in milliseconds for an avd to finish its * boot animations (default 120000). + * @since 0.18.0 */ String AVD_READY_TIMEOUT = "avdReadyTimeout"; @@ -154,8 +177,59 @@ public interface AndroidMobileCapabilityType extends CapabilityType { */ String CHROMEDRIVER_EXECUTABLE = "chromedriverExecutable"; + /** + * An array of arguments to be passed to the chromedriver binary when it's run by Appium. + * By default no CLI args are added beyond what Appium uses internally (such as {@code --url-base}, {@code --port}, + * {@code --adb-port}, and {@code --log-path}. + * @since 1.12.0 + */ + String CHROMEDRIVER_ARGS = "chromedriverArgs"; + + /** + * The absolute path to a directory to look for Chromedriver executables in, for automatic discovery of compatible + * Chromedrivers. Ignored if {@code chromedriverUseSystemExecutable} is {@code true} + * @since 1.8.0 + */ + String CHROMEDRIVER_EXECUTABLE_DIR = "chromedriverExecutableDir"; + + /** + * The absolute path to a file which maps Chromedriver versions to the minimum Chrome that it supports. + * Ignored if {@code chromedriverUseSystemExecutable} is {@code true} + * @since 1.8.0 + */ + String CHROMEDRIVER_CHROME_MAPPING_FILE = "chromedriverChromeMappingFile"; + + /** + * If true, bypasses automatic Chromedriver configuration and uses the version that comes downloaded with Appium. + * Ignored if {@code chromedriverExecutable} is set. Defaults to {@code false} + * @since 1.9.0 + */ + String CHROMEDRIVER_USE_SYSTEM_EXECUTABLE = "chromedriverUseSystemExecutable"; + + /** + * Numeric port to start Chromedriver on. Note that use of this capability is discouraged as it will cause undefined + * behavior in case there are multiple webviews present. By default Appium will find a free port. + */ + String CHROMEDRIVER_PORT = "chromedriverPort"; + + /** + * A list of valid ports for Appium to use for communication with Chromedrivers. This capability supports multiple + * webview scenarios. The form of this capability is an array of numeric ports, where array items can themselves be + * arrays of length 2, where the first element is the start of an inclusive range and the second is the end. + * By default, Appium will use any free port. + * @since 1.13.0 + */ + String CHROMEDRIVER_PORTS = "chromedriverPorts"; + + /** + * Sets the chromedriver flag {@code --disable-build-check} for Chrome webview tests. + * @since 1.11.0 + */ + String CHROMEDRIVER_DISABLE_BUILD_CHECK = "chromedriverDisableBuildCheck"; + /** * Amount of time to wait for Webview context to become active, in ms. Defaults to 2000. + * @since 1.5.2 */ String AUTO_WEBVIEW_TIMEOUT = "autoWebviewTimeout"; @@ -190,11 +264,13 @@ public interface AndroidMobileCapabilityType extends CapabilityType { * the test app using adb. In other words, with dontStopAppOnReset set to true, * we will not include the -S flag in the adb shell am start call. * With this capability omitted or set to false, we include the -S flag. Default false + * @since 1.4.0 */ String DONT_STOP_APP_ON_RESET = "dontStopAppOnReset"; /** * Enable Unicode input, default false. + * @since 1.2.0 */ String UNICODE_KEYBOARD = "unicodeKeyboard"; @@ -207,6 +283,7 @@ public interface AndroidMobileCapabilityType extends CapabilityType { /** * Skip checking and signing of app with debug keys, will work only with * UiAutomator and not with selendroid, default false. + * @since 1.2.2 */ String NO_SIGN = "noSign"; @@ -223,6 +300,7 @@ public interface AndroidMobileCapabilityType extends CapabilityType { * Disables android watchers that watch for application not responding and application crash, * this will reduce cpu usage on android device/emulator. This capability will work only with * UiAutomator and not with selendroid, default false. + * @since 1.4.0 */ String DISABLE_ANDROID_WATCHERS = "disableAndroidWatchers"; @@ -243,18 +321,57 @@ public interface AndroidMobileCapabilityType extends CapabilityType { /** * In a web context, use native (adb) method for taking a screenshot, rather than proxying * to ChromeDriver, default false. + * @since 1.5.3 */ String NATIVE_WEB_SCREENSHOT = "nativeWebScreenshot"; /** * The name of the directory on the device in which the screenshot will be put. * Defaults to /data/local/tmp. + * @since 1.6.0 */ String ANDROID_SCREENSHOT_PATH = "androidScreenshotPath"; + /** + * Set the network speed emulation. Specify the maximum network upload and download speeds. Defaults to {@code full} + */ + String NETWORK_SPEED = "networkSpeed"; + + /** + * Toggle gps location provider for emulators before starting the session. By default the emulator will have this + * option enabled or not according to how it has been provisioned. + */ + String GPS_ENABLED = "gpsEnabled"; + + /** + * Set this capability to {@code true} to run the Emulator headless when device display is not needed to be visible. + * {@code false} is the default value. isHeadless is also support for iOS, check XCUITest-specific capabilities. + */ + String IS_HEADLESS = "isHeadless"; + + /** + * Timeout in milliseconds used to wait for adb command execution. Defaults to {@code 20000} + */ + String ADB_EXEC_TIMEOUT = "adbExecTimeout"; + + /** + * Sets the locale for more details. */ String SYSTEM_PORT = "systemPort"; + + /** + * Optional remote ADB server host. + * @since 1.7.0 + */ + String REMOTE_ADB_HOST = "remoteAdbHost"; + + /** + * Skips unlock during session creation. Defaults to {@code false} + */ + String SKIP_UNLOCK = "skipUnlock"; + + /** + * Unlock the target device with particular lock pattern instead of just waking up the device with a helper app. + * It works with {@code unlockKey} capability. Defaults to undefined. {@code fingerprint} is available only for + * Android 6.0+ and emulators. + * Read unlock doc in + * android driver. + */ + String UNLOCK_TYPE = "unlockType"; + + /** + * A key pattern to unlock used by {@code unlockType}. + */ + String UNLOCK_KEY = "unlockKey"; + + /** + * Initializing the app under test automatically. + * Appium does not launch the app under test if this is {@code false}. Defaults to {@code true} + */ + String AUTO_LAUNCH = "autoLaunch"; + + /** + * Skips to start capturing logcat. It might improve performance such as network. + * Log related commands will not work. Defaults to {@code false}. + * @since 1.12.0 + */ + String SKIP_LOGCAT_CAPTURE = "skipLogcatCapture"; + + /** + * A package, list of packages or * to uninstall package/s before installing apks for test. + * {@code '*'} uninstall all of thrid-party packages except for packages which is necessary for Appium to test such + * as {@code io.appium.settings} or {@code io.appium.uiautomator2.server} since Appium already contains the logic to + * manage them. + * @since 1.12.0 + */ + String UNINSTALL_OTHER_PACKAGES = "uninstallOtherPackages"; + + /** + * Set device animation scale zero if the value is {@code true}. After session is complete, Appium restores the + * animation scale to it's original value. Defaults to {@code false} + * @since 1.9.0 + */ + String DISABLE_WINDOW_ANIMATION = "disableWindowAnimation"; } From f11fe00a536d6c6a81eeb3b0d130607572b0887e Mon Sep 17 00:00:00 2001 From: Takeshi Kishi Date: Tue, 24 Sep 2019 01:59:16 +0900 Subject: [PATCH 036/675] feat: Make settings api to accept string names (#1240) --- src/main/java/io/appium/java_client/HasSettings.java | 12 ++++++++++++ .../java/io/appium/java_client/MobileCommand.java | 4 ++-- .../io/appium/java_client/android/SettingTest.java | 11 +++++++++++ .../java/io/appium/java_client/ios/SettingTest.java | 11 +++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/appium/java_client/HasSettings.java b/src/main/java/io/appium/java_client/HasSettings.java index 3195bcf58..4a8bdfbff 100644 --- a/src/main/java/io/appium/java_client/HasSettings.java +++ b/src/main/java/io/appium/java_client/HasSettings.java @@ -37,6 +37,18 @@ public interface HasSettings extends ExecutesMethod { * @param value value of the setting. */ default void setSetting(Setting setting, Object value) { + CommandExecutionHelper.execute(this, setSettingsCommand(setting.toString(), value)); + } + + /** + * 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(String setting, Object value) { CommandExecutionHelper.execute(this, setSettingsCommand(setting, value)); } diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index aaf855468..ab0d3d756 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -469,9 +469,9 @@ public static ImmutableMap prepareArguments(String[] params, return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.of()); } - public static Map.Entry> setSettingsCommand(Setting setting, Object value) { + public static Map.Entry> setSettingsCommand(String setting, Object value) { return new AbstractMap.SimpleEntry<>(SET_SETTINGS, prepareArguments("settings", - prepareArguments(setting.toString(), value))); + prepareArguments(setting, value))); } /** 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 0cd0ac6f5..559c1ba69 100644 --- a/src/test/java/io/appium/java_client/android/SettingTest.java +++ b/src/test/java/io/appium/java_client/android/SettingTest.java @@ -92,6 +92,17 @@ public class SettingTest extends BaseAndroidTest { .get(Setting.TRACK_SCROLL_EVENTS.toString())); } + @Test public void testSettingByString() { + assertEquals(true, driver.getSettings() + .get("shouldUseCompactResponses")); + driver.setSetting("shouldUseCompactResponses", false); + assertEquals(false, driver.getSettings() + .get("shouldUseCompactResponses")); + driver.setSetting("shouldUseCompactResponses", true); + assertEquals(true, driver.getSettings() + .get("shouldUseCompactResponses")); + } + private void assertJSONElementContains(Setting setting, long value) { assertEquals(driver.getSettings().get(setting.toString()), value); } diff --git a/src/test/java/io/appium/java_client/ios/SettingTest.java b/src/test/java/io/appium/java_client/ios/SettingTest.java index b6d576585..d48d2c64d 100644 --- a/src/test/java/io/appium/java_client/ios/SettingTest.java +++ b/src/test/java/io/appium/java_client/ios/SettingTest.java @@ -83,5 +83,16 @@ public class SettingTest extends AppIOSTest { .get(Setting.KEYBOARD_PREDICTION.toString())); } + @Test public void testSettingByString() { + assertEquals(true, driver.getSettings() + .get("shouldUseCompactResponses")); + driver.setSetting("shouldUseCompactResponses", false); + assertEquals(false, driver.getSettings() + .get("shouldUseCompactResponses")); + driver.setSetting("shouldUseCompactResponses", true); + assertEquals(true, driver.getSettings() + .get("shouldUseCompactResponses")); + } + } From 53814cd5ac77cf26e73c89eee49649af39f9c5a5 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Sep 2019 07:26:23 +0200 Subject: [PATCH 037/675] fix: Avoid throwing null pointer exception if any of settings is equal to null (#1241) --- src/main/java/io/appium/java_client/HasSettings.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/io/appium/java_client/HasSettings.java b/src/main/java/io/appium/java_client/HasSettings.java index 4a8bdfbff..2db441b57 100644 --- a/src/main/java/io/appium/java_client/HasSettings.java +++ b/src/main/java/io/appium/java_client/HasSettings.java @@ -63,8 +63,6 @@ default void setSetting(String setting, Object value) { default Map getSettings() { Map.Entry> keyValuePair = getSettingsCommand(); Response response = execute(keyValuePair.getKey(), keyValuePair.getValue()); - - return ImmutableMap.builder() - .putAll(Map.class.cast(response.getValue())).build(); + return (Map) response.getValue(); } } From 5aa800994d87607ac1e21aab8273bde6dd1b2ea2 Mon Sep 17 00:00:00 2001 From: Mori Atsushi Date: Sat, 5 Oct 2019 23:24:13 +0900 Subject: [PATCH 038/675] Fix typo (#1250) --- .../io/appium/java_client/android/nativekey/AndroidKey.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/appium/java_client/android/nativekey/AndroidKey.java b/src/main/java/io/appium/java_client/android/nativekey/AndroidKey.java index fb82b1abc..c0a809801 100644 --- a/src/main/java/io/appium/java_client/android/nativekey/AndroidKey.java +++ b/src/main/java/io/appium/java_client/android/nativekey/AndroidKey.java @@ -1021,7 +1021,7 @@ public enum AndroidKey { * Key code constant: Media Top Menu key. * Goes to the top of media menu. */ - _MEDIA_TOP_MENU(226), + MEDIA_TOP_MENU(226), /** * Key code constant: '11' key. */ @@ -1178,7 +1178,7 @@ public enum AndroidKey { * Goes to the context menu of media contents. Corresponds to Media Context-sensitive * Menu (0x11) of CEC User Control Code. */ - _TV_MEDIA_CONTEXT_MENU(257), + TV_MEDIA_CONTEXT_MENU(257), /** * Key code constant: Timer programming key. * Goes to the timer recording menu. Corresponds to Timer Programming (0x54) of From f5470d9cf355e56023f4a14dba4e80af5ea840fc Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Tue, 8 Oct 2019 16:49:08 +0100 Subject: [PATCH 039/675] Revert "Upgraded Selenium version to alpha 2. (#1210)" This reverts commit 7239a9d44cd088b6c457c93ac8a90a4cf797dd17. --- gradle.properties | 2 +- .../appium/java_client/remote/AppiumCommandExecutor.java | 2 +- .../java_client/remote/AppiumW3CHttpCommandCodec.java | 2 +- .../java_client/android/OpenNotificationsTest.java | 3 +-- .../io/appium/java_client/android/UIAutomator2Test.java | 9 ++++----- .../element/generation/ios/IOSElementGenerationTest.java | 5 ++--- .../java/io/appium/java_client/ios/IOSAlertTest.java | 3 +-- .../java/io/appium/java_client/ios/IOSDriverTest.java | 9 ++++----- .../java/io/appium/java_client/ios/IOSElementTest.java | 3 +-- .../java_client/ios/IOSNativeWebTapSettingTest.java | 7 +++---- .../java/io/appium/java_client/ios/IOSTouchTest.java | 4 ++-- .../java/io/appium/java_client/ios/IOSWebViewTest.java | 7 ++----- .../java_client/pagefactory_tests/XCUITModeTest.java | 3 +-- 13 files changed, 24 insertions(+), 35 deletions(-) diff --git a/gradle.properties b/gradle.properties index 63b13d41e..9bd535700 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ signing.secretKeyRingFile=PathToYourKeyRingFile ossrhUsername=your-jira-id ossrhPassword=your-jira-password -selenium.version=4.0.0-alpha-2 \ No newline at end of file +selenium.version=3.141.59 diff --git a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java index 707680b4f..3f094ff53 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -44,10 +44,10 @@ import org.openqa.selenium.remote.ProtocolHandshake; import org.openqa.selenium.remote.Response; import org.openqa.selenium.remote.ResponseCodec; -import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; import org.openqa.selenium.remote.http.HttpClient; import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; +import org.openqa.selenium.remote.http.W3CHttpCommandCodec; import org.openqa.selenium.remote.service.DriverService; import java.io.BufferedInputStream; diff --git a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java index 0fe0ace05..aec7ebd75 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java +++ b/src/main/java/io/appium/java_client/remote/AppiumW3CHttpCommandCodec.java @@ -32,7 +32,7 @@ import org.openqa.selenium.interactions.KeyInput; import org.openqa.selenium.interactions.Sequence; -import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec; +import org.openqa.selenium.remote.http.W3CHttpCommandCodec; import java.util.Collection; import java.util.Map; diff --git a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java index d6af69d05..7806ecc14 100644 --- a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java +++ b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java @@ -1,6 +1,5 @@ package io.appium.java_client.android; -import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertNotEquals; import static org.openqa.selenium.By.id; @@ -15,7 +14,7 @@ public class OpenNotificationsTest extends BaseAndroidTest { public void openNotification() { driver.closeApp(); driver.openNotifications(); - WebDriverWait wait = new WebDriverWait(driver, ofSeconds(20)); + WebDriverWait wait = new WebDriverWait(driver, 20); assertNotEquals(0, wait.until(input -> { List result = input .findElements(id("com.android.systemui:id/settings_button")); diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java index bca878dda..19df3618a 100644 --- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java +++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java @@ -1,6 +1,5 @@ package io.appium.java_client.android; -import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -24,7 +23,7 @@ public void afterMethod() { @Test public void testLandscapeRightRotation() { - new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions + new WebDriverWait(driver, 20).until(ExpectedConditions .elementToBeClickable(driver.findElementById("android:id/content") .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90); @@ -34,7 +33,7 @@ public void testLandscapeRightRotation() { @Test public void testLandscapeLeftRotation() { - new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions + new WebDriverWait(driver, 20).until(ExpectedConditions .elementToBeClickable(driver.findElementById("android:id/content") .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270); @@ -44,7 +43,7 @@ public void testLandscapeLeftRotation() { @Test public void testPortraitUpsideDown() { - new WebDriverWait(driver, ofSeconds(20)).until(ExpectedConditions + new WebDriverWait(driver, 20).until(ExpectedConditions .elementToBeClickable(driver.findElementById("android:id/content") .findElement(MobileBy.AccessibilityId("Graphics")))); DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180); @@ -57,7 +56,7 @@ public void testPortraitUpsideDown() { */ @Ignore public void testToastMSGIsDisplayed() { - final WebDriverWait wait = new WebDriverWait(driver, ofSeconds(30)); + final WebDriverWait wait = new WebDriverWait(driver, 30); Activity activity = new Activity("io.appium.android.apis", ".view.PopupMenu1"); driver.startActivity(activity); diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java index 7ed8832e5..0b7572be3 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -1,7 +1,6 @@ package io.appium.java_client.appium.element.generation.ios; import static io.appium.java_client.MobileBy.AccessibilityId; -import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertTrue; import static org.openqa.selenium.By.id; import static org.openqa.selenium.By.name; @@ -85,11 +84,11 @@ public void whenIOSHybridAppIsLaunched() { Capabilities caps = commonAppCapabilitiesSupplier.get(); return caps.merge(appFileSupplierFunction.apply(webViewApp).get()); }, (by, aClass) -> { - new WebDriverWait(driver, ofSeconds(30)) + new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(id("login"))) .click(); driver.findElementByAccessibilityId("webView").click(); - new WebDriverWait(driver, ofSeconds(30)) + new WebDriverWait(driver, 30) .until(ExpectedConditions .presenceOfElementLocated(AccessibilityId("Webview"))); try { diff --git a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java index 7c46a3c4d..06df51bd7 100644 --- a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java @@ -16,7 +16,6 @@ package io.appium.java_client.ios; -import static java.time.Duration.ofSeconds; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertTrue; import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; @@ -33,7 +32,7 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class IOSAlertTest extends AppIOSTest { - private WebDriverWait waiting = new WebDriverWait(driver, ofSeconds(10000)); + private WebDriverWait waiting = new WebDriverWait(driver, 10000); private static final String iOSAutomationText = "show alert"; @Test public void acceptAlertTest() { diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 69056af48..995ac4c58 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -16,7 +16,6 @@ package io.appium.java_client.ios; -import static java.time.Duration.ofSeconds; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -57,7 +56,7 @@ public void getDeviceTimeTest() { } @Test public void hideKeyboardWithParametersTest() { - new WebDriverWait(driver, ofSeconds(30)) + new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(By.id("IntegerA"))) .click(); driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done"); @@ -103,7 +102,7 @@ public void getDeviceTimeTest() { @Test public void putAppIntoBackgroundAndRestoreTest() { final long msStarted = System.currentTimeMillis(); - driver.runAppInBackground(ofSeconds(4)); + driver.runAppInBackground(Duration.ofSeconds(4)); assertThat(System.currentTimeMillis() - msStarted, greaterThan(3000L)); } @@ -120,7 +119,7 @@ public void getDeviceTimeTest() { } assertThat(driver.queryAppState(BUNDLE_ID), equalTo(ApplicationState.RUNNING_IN_FOREGROUND)); Thread.sleep(500); - driver.runAppInBackground(ofSeconds(-1)); + driver.runAppInBackground(Duration.ofSeconds(-1)); assertThat(driver.queryAppState(BUNDLE_ID), lessThan(ApplicationState.RUNNING_IN_FOREGROUND)); Thread.sleep(500); driver.activateApp(BUNDLE_ID); @@ -129,7 +128,7 @@ public void getDeviceTimeTest() { @Test public void putAIntoBackgroundWithoutRestoreTest() { assertThat(driver.findElementsById("IntegerA"), is(not(empty()))); - driver.runAppInBackground(ofSeconds(-1)); + driver.runAppInBackground(Duration.ofSeconds(-1)); assertThat(driver.findElementsById("IntegerA"), is(empty())); driver.launchApp(); } diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/test/java/io/appium/java_client/ios/IOSElementTest.java index 18bbf0d69..4389d1888 100644 --- a/src/test/java/io/appium/java_client/ios/IOSElementTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSElementTest.java @@ -1,6 +1,5 @@ package io.appium.java_client.ios; -import static java.time.Duration.ofSeconds; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; @@ -26,7 +25,7 @@ public void findByAccessibilityIdTest() { @Ignore @Test public void setValueTest() { - WebDriverWait wait = new WebDriverWait(driver, ofSeconds(20)); + WebDriverWait wait = new WebDriverWait(driver, 20); IOSElement slider = wait.until( driver1 -> driver1.findElement(By.className("XCUIElementTypeSlider"))); 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 25746f91b..de8bcbb36 100644 --- a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java @@ -1,6 +1,5 @@ package io.appium.java_client.ios; -import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -18,17 +17,17 @@ public class IOSNativeWebTapSettingTest extends BaseSafariTest { driver.nativeWebTap(true); WebElement el = driver.findElementById("i am a link"); el.click(); - assertTrue(new WebDriverWait(driver, ofSeconds(30)) + assertTrue(new WebDriverWait(driver, 30) .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs"))); driver.navigate().back(); // now do a click with it turned off and assert the same behavior - assertTrue(new WebDriverWait(driver, ofSeconds(30)) + assertTrue(new WebDriverWait(driver, 30) .until(ExpectedConditions.titleIs("I am a page title - Sauce Labs"))); driver.nativeWebTap(false); el = driver.findElementById("i am a link"); el.click(); - assertTrue(new WebDriverWait(driver, ofSeconds(30)) + assertTrue(new WebDriverWait(driver, 30) .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs"))); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java index 8b6d34b04..ea2f83d9d 100644 --- a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java @@ -58,7 +58,7 @@ public void touchWithPressureTest() { } @Test public void swipeTest() { - WebDriverWait webDriverWait = new WebDriverWait(driver, ofSeconds(30)); + WebDriverWait webDriverWait = new WebDriverWait(driver, 30); IOSElement slider = webDriverWait.until(driver1 -> driver.findElementByClassName("XCUIElementTypeSlider")); Dimension size = slider.getSize(); @@ -82,7 +82,7 @@ public void touchWithPressureTest() { new MultiTouchAction(driver).add(tap1).add(tap2).perform(); - WebDriverWait waiting = new WebDriverWait(driver, ofSeconds(10000)); + WebDriverWait waiting = new WebDriverWait(driver, 10000); assertNotNull(waiting.until(alertIsPresent())); driver.switchTo().alert().accept(); } diff --git a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java index d12d5aa16..7c8f380c3 100644 --- a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java @@ -1,6 +1,5 @@ package io.appium.java_client.ios; -import static java.time.Duration.ofSeconds; import static org.junit.Assert.assertTrue; import io.appium.java_client.MobileBy; @@ -10,16 +9,14 @@ import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -import java.time.Duration; - public class IOSWebViewTest extends BaseIOSWebViewTest { @Test public void webViewPageTestCase() throws InterruptedException { - new WebDriverWait(driver, ofSeconds(30)) + new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(By.id("login"))) .click(); driver.findElementByAccessibilityId("webView").click(); - new WebDriverWait(driver, ofSeconds(30)) + new WebDriverWait(driver, 30) .until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("Webview"))); findAndSwitchToWebView(); WebElement el = driver.findElementByPartialLinkText("login"); diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java index cd683709b..c54bf9129 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java @@ -19,7 +19,6 @@ import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE; import static io.appium.java_client.pagefactory.LocatorGroupStrategy.CHAIN; -import static java.time.Duration.ofSeconds; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -48,7 +47,7 @@ public class XCUITModeTest extends AppIOSTest { private boolean populated = false; - private WebDriverWait waiting = new WebDriverWait(driver, ofSeconds(10000)); + private WebDriverWait waiting = new WebDriverWait(driver, 10000); @HowToUseLocators(iOSXCUITAutomation = ALL_POSSIBLE) @iOSXCUITFindBy(iOSNsPredicate = "label contains 'Compute'") From 75135e2d521905f64c3275ba874ecbd9904afa19 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 18 Oct 2019 21:48:34 +0200 Subject: [PATCH 040/675] refactor: Update the implementation of Appium executables detection (#1256) --- .../local/AppiumDriverLocalService.java | 60 ++-- .../service/local/AppiumServiceBuilder.java | 281 +++++++----------- .../local/InvalidServerInstanceException.java | 8 +- .../java_client/service/local/Scripts.java | 80 ----- src/main/resources/scripts/getExe.js | 1 - .../scripts/get_path_to_default_node.sh | 4 - .../java/io/appium/java_client/TestUtils.java | 16 + .../io/appium/java_client/ios/AppIOSTest.java | 4 +- .../appium/java_client/ios/BaseIOSTest.java | 12 +- .../java_client/ios/BaseIOSWebViewTest.java | 5 +- .../java_client/ios/BaseSafariTest.java | 5 +- .../java_client/ios/UICatalogIOSTest.java | 5 +- .../service/local/ServerBuilderTest.java | 103 ++++--- 13 files changed, 230 insertions(+), 354 deletions(-) delete mode 100644 src/main/java/io/appium/java_client/service/local/Scripts.java delete mode 100644 src/main/resources/scripts/getExe.js delete mode 100644 src/main/resources/scripts/get_path_to_default_node.sh create mode 100644 src/test/java/io/appium/java_client/TestUtils.java diff --git a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java index a7fd502b2..c3f9e0389 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java @@ -17,6 +17,7 @@ package io.appium.java_client.service.local; import static com.google.common.base.Preconditions.checkNotNull; +import static io.appium.java_client.service.local.AppiumServiceBuilder.BROADCAST_IP_ADDRESS; import static org.slf4j.event.Level.DEBUG; import static org.slf4j.event.Level.INFO; @@ -67,8 +68,8 @@ public final class AppiumDriverLocalService extends DriverService { private CommandLine process = null; AppiumDriverLocalService(String ipAddress, File nodeJSExec, int nodeJSPort, - ImmutableList nodeJSArgs, ImmutableMap nodeJSEnvironment, - long startupTimeout, TimeUnit timeUnit) throws IOException { + ImmutableList nodeJSArgs, ImmutableMap nodeJSEnvironment, + long startupTimeout, TimeUnit timeUnit) throws IOException { super(nodeJSExec, nodeJSPort, nodeJSArgs, nodeJSEnvironment); this.nodeJSExec = nodeJSExec; this.nodeJSArgs = nodeJSArgs; @@ -91,11 +92,13 @@ public static AppiumDriverLocalService buildService(AppiumServiceBuilder builder * * @return The base URL for the managed appium server. */ - @Override public URL getUrl() { + @Override + public URL getUrl() { return url; } - @Override public boolean isRunning() { + @Override + public boolean isRunning() { lock.lock(); try { if (process == null) { @@ -121,15 +124,15 @@ public static AppiumDriverLocalService buildService(AppiumServiceBuilder builder } private void ping(long time, TimeUnit timeUnit) throws UrlChecker.TimeoutException, MalformedURLException { - URL status = new URL(url.toString() + "/status"); + // The operating system might block direct access to the universal broadcast IP address + URL status = new URL(url.toString().replace(BROADCAST_IP_ADDRESS, "127.0.0.1") + "/status"); new UrlChecker().waitUntilAvailable(time, timeUnit, status); } /** * Starts the defined appium server. * - * @throws AppiumServerHasNotBeenStartedLocallyException - * If an error occurs while spawning the child process. + * @throws AppiumServerHasNotBeenStartedLocallyException If an error occurs while spawning the child process. * @see #stop() */ public void start() throws AppiumServerHasNotBeenStartedLocallyException { @@ -141,7 +144,7 @@ public void start() throws AppiumServerHasNotBeenStartedLocallyException { try { process = new CommandLine(this.nodeJSExec.getCanonicalPath(), - nodeJSArgs.toArray(new String[] {})); + nodeJSArgs.toArray(new String[]{})); process.setEnvironmentVariables(nodeJSEnvironment); process.copyOutputTo(stream); process.executeAsync(); @@ -149,8 +152,8 @@ public void start() throws AppiumServerHasNotBeenStartedLocallyException { } catch (Throwable e) { destroyProcess(); String msgTxt = "The local appium server has not been started. " - + "The given Node.js executable: " + this.nodeJSExec.getAbsolutePath() - + " Arguments: " + nodeJSArgs.toString() + " " + "\n"; + + "The given Node.js executable: " + this.nodeJSExec.getAbsolutePath() + + " Arguments: " + nodeJSArgs.toString() + " " + "\n"; if (process != null) { String processStream = process.getStdOut(); if (!StringUtils.isBlank(processStream)) { @@ -171,7 +174,8 @@ public void start() throws AppiumServerHasNotBeenStartedLocallyException { * * @see #start() */ - @Override public void stop() { + @Override + public void stop() { lock.lock(); try { if (process != null) { @@ -192,8 +196,7 @@ private void destroyProcess() { /** * Logs as string. * - * @return String logs if the server has been run. - * null is returned otherwise. + * @return String logs if the server has been run. Null is returned otherwise. */ @Nullable public String getStdOut() { @@ -206,6 +209,7 @@ public String getStdOut() { /** * Adds other output stream which should accept server output data. + * * @param outputStream is an instance of {@link OutputStream} * that is ready to accept server output */ @@ -216,6 +220,7 @@ public void addOutPutStream(OutputStream outputStream) { /** * Adds other output streams which should accept server output data. + * * @param outputStreams is a list of additional {@link OutputStream} * that are ready to accept server output */ @@ -240,12 +245,12 @@ public boolean clearOutPutStreams() { * SLF4J loggers. This allow server output * data to be configured with your preferred logging frameworks (e.g. * java.util.logging, logback, log4j). - * + * *

NOTE1: You might want to call method {@link #clearOutPutStreams()} before * calling this method.
* NOTE2: it is required that {@code --log-timestamp} server flag is * {@code false}. - * + * *

By default log messages are: *