diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 531000b79..72a15d717 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -24,4 +24,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: gradle/wrapper-validation-action@v2 + - uses: gradle/actions/wrapper-validation@v3 diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c293b7b40..c83581927 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -37,7 +37,7 @@ jobs: platform: macos-12 e2e-tests: ios - java: 17 - platform: macos-latest + platform: ubuntu-latest e2e-tests: android - java: 21 platform: ubuntu-latest @@ -49,6 +49,13 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Enable KVM group perms + if: matrix.e2e-tests == 'android' + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@v4 with: @@ -81,11 +88,11 @@ jobs: if: matrix.e2e-tests == 'android' uses: reactivecircus/android-emulator-runner@v2 with: - script: ./gradlew uiAutomationTest -PisCI -Pselenium.version=$latest_snapshot + script: ./gradlew e2eAndroidTest -PisCI -Pselenium.version=$latest_snapshot api-level: ${{ env.ANDROID_SDK_VERSION }} avd-name: ${{ env.ANDROID_EMU_NAME }} - sdcard-path-or-size: 1500M disable-spellchecker: true + disable-animations: true target: ${{ env.ANDROID_EMU_TARGET }} - name: Select Xcode @@ -108,4 +115,4 @@ jobs: xcrun simctl bootstatus $target_sim_id -b - name: Run iOS E2E tests if: matrix.e2e-tests == 'ios' - run: ./gradlew xcuiTest -PisCI -Pselenium.version=$latest_snapshot + run: ./gradlew e2eIosTest -PisCI -Pselenium.version=$latest_snapshot diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index f3387333b..393ca3bd6 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -8,8 +8,8 @@ jobs: name: https://www.conventionalcommits.org runs-on: ubuntu-latest steps: - - uses: beemojs/conventional-pr-action@v2 + - uses: beemojs/conventional-pr-action@v3 with: - config-preset: angular + config-preset: angular env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 92823038c..44838a04f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +_9.2.3_ +- **[BUG FIX]** + - Properly represent `FeaturesMatchingResult` model if `multiple` option is enabled [#2170](https://github.com/appium/java-client/pull/2170) + - Use current class loader for the ByteBuddy wrapper [#2172](https://github.com/appium/java-client/pull/2172) \ + This fixes errors like `NoClassDefFoundError: org/openqa/selenium/remote/RemoteWebElement`, `NoClassDefFoundError: io/appium/java_client/proxy/HasMethodCallListeners` when `PageFactory` is used. + - Correct extension name for `mobile: replaceElementValue` [#2171](https://github.com/appium/java-client/pull/2171) +- **[DEPRECATION]** + - Deprecate `AppiumProtocolHandshake` class [#2173](https://github.com/appium/java-client/pull/2173) \ + The original `ProtocolHandshake` class only supports W3C protocol now. There is no need to hack it anymore. +- **[REFACTOR]** + - Replace Guava `HttpHeaders` with Selenium `HttpHeader` [#2151](https://github.com/appium/java-client/pull/2151) +- **[DEPENDENCY CHANGE]** + - Bump SLF4J from `2.0.12` to `2.0.13` [#2158](https://github.com/appium/java-client/pull/2158) + - Bump Gson from `2.10.1` to `2.11.0` [#2175](https://github.com/appium/java-client/pull/2175) + _9.2.2_ - **[BUG FIX]** - fix: Fix building of Android key event parameters [#2145](https://github.com/appium/java-client/pull/2145) diff --git a/README.md b/README.md index 189592d79..6b7f4988e 100644 --- a/README.md +++ b/README.md @@ -93,16 +93,16 @@ dependencies { ``` ### Compatibility Matrix - Appium Java Client | Selenium client -----------------------------------------------------------------------------------|----------------- - `9.2.1`(known issues: appium/java-client#2145, appium/java-client#2146), `9.2.2` | `4.19.0` - `9.1.0`, `9.2.0` | `4.17.0`, `4.18.0`, `4.18.1` - `9.0.0` | `4.14.1`, `4.15.0`, `4.16.0` (partially [corrupted](https://github.com/SeleniumHQ/selenium/issues/13256)), `4.16.1` - N/A | `4.14.0` - `8.5.0`, `8.5.1`, `8.6.0` | `4.9.1`, `4.10.0`, `4.11.0`, `4.12.0`, `4.12.1` (known issue: appium/java-client#2004), `4.13.0` - `8.4.0` | `4.8.2`, `4.8.3`, `4.9.0` - `8.3.0` | `4.7.0`, `4.7.1`, `4.7.2`, `4.8.0`, `4.8.1` - `8.2.1` | `4.5.0`, `4.5.1`, `4.5.2`, `4.5.3`, `4.6.0` + Appium Java Client | Selenium client +-------------------------------------------------------------------------------------------|----------------- + `9.2.1`(known issues: appium/java-client#2145, appium/java-client#2146), `9.2.2`, `9.2.3` | `4.19.0`, `4.19.1`, `4.20.0`, `4.21.0` + `9.1.0`, `9.2.0` | `4.17.0`, `4.18.0`, `4.18.1` + `9.0.0` | `4.14.1`, `4.15.0`, `4.16.0` (partially [corrupted](https://github.com/SeleniumHQ/selenium/issues/13256)), `4.16.1` + N/A | `4.14.0` + `8.5.0`, `8.5.1`, `8.6.0` | `4.9.1`, `4.10.0`, `4.11.0`, `4.12.0`, `4.12.1` (known issue: appium/java-client#2004), `4.13.0` + `8.4.0` | `4.8.2`, `4.8.3`, `4.9.0` + `8.3.0` | `4.7.0`, `4.7.1`, `4.7.2`, `4.8.0`, `4.8.1` + `8.2.1` | `4.5.0`, `4.5.1`, `4.5.2`, `4.5.3`, `4.6.0` #### Why is it so complicated? diff --git a/build.gradle b/build.gradle index 4197aa34a..54057da0c 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { id 'maven-publish' id 'jacoco' id 'signing' - id 'org.owasp.dependencycheck' version '9.0.10' + id 'org.owasp.dependencycheck' version '9.2.0' id 'com.github.johnrengelman.shadow' version '8.1.1' } @@ -34,7 +34,7 @@ java { ext { seleniumVersion = project.property('selenium.version') appiumClientVersion = project.property('appiumClient.version') - slf4jVersion = '2.0.12' + slf4jVersion = '2.0.13' } dependencies { @@ -65,17 +65,8 @@ dependencies { } } } - implementation 'com.google.code.gson:gson:2.10.1' + implementation 'com.google.code.gson:gson:2.11.0' implementation "org.slf4j:slf4j-api:${slf4jVersion}" - - testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - testImplementation 'org.hamcrest:hamcrest:2.2' - testImplementation (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.7.0') { - exclude group: 'org.seleniumhq.selenium' - } - testImplementation "org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}" - testRuntimeOnly "org.slf4j:slf4j-simple:${slf4jVersion}" } dependencyCheck { @@ -199,51 +190,104 @@ processResources { ] } -test { - useJUnitPlatform() - testLogging.showStandardStreams = true - testLogging.exceptionFormat = 'full' - filter { - includeTestsMatching 'io.appium.java_client.android.geolocation.*' - includeTestsMatching 'io.appium.java_client.drivers.options.*' - includeTestsMatching 'io.appium.java_client.events.*' - includeTestsMatching 'io.appium.java_client.internal.*' - includeTestsMatching 'io.appium.java_client.pagefactory_tests.DesktopBrowserCompatibilityTest' - includeTestsMatching 'io.appium.java_client.pagefactory_tests.TimeoutTest' - includeTestsMatching 'io.appium.java_client.proxy.*' - includeTestsMatching 'io.appium.java_client.remote.*' - includeTestsMatching 'io.appium.java_client.touch.*' - } - finalizedBy jacocoTestReport -} +testing { + suites { + configureEach { + useJUnitJupiter() + dependencies { + implementation 'org.junit.jupiter:junit-jupiter:5.10.2' + runtimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.hamcrest:hamcrest:2.2' + runtimeOnly "org.slf4j:slf4j-simple:${slf4jVersion}" + } + targets.configureEach { + testTask.configure { + testLogging { + showStandardStreams = true + exceptionFormat = 'full' + } + } + } + } -tasks.register('xcuiTest', Test) { - useJUnitPlatform() - testLogging.showStandardStreams = true - testLogging.exceptionFormat = 'full' - filter { - includeTestsMatching 'io.appium.java_client.ios.*' - includeTestsMatching '*.pagefactory_tests.XCUITModeTest' - includeTestsMatching '*.pagefactory_tests.widget.tests.combined.*' - includeTestsMatching '*.pagefactory_tests.widget.tests.ios.*' - includeTestsMatching 'io.appium.java_client.service.local.StartingAppLocallyIosTest' - exclude '**/IOSScreenRecordTest.class' - exclude '**/ImagesComparisonTest.class' - } -} + test { + dependencies { + implementation "org.seleniumhq.selenium:selenium-chrome-driver:${seleniumVersion}" + implementation('io.github.bonigarcia:webdrivermanager:5.8.0') { + exclude group: 'org.seleniumhq.selenium' + } + } + targets.configureEach { + testTask.configure { + finalizedBy jacocoTestReport + } + } + } + + e2eIosTest(JvmTestSuite) { + sources { + java { + srcDirs = ['src/e2eIosTest/java'] + } + } + dependencies { + implementation project() + implementation(sourceSets.test.output) + implementation('org.apache.commons:commons-lang3:3.14.0') + } -tasks.register('uiAutomationTest', Test) { - useJUnitPlatform() - testLogging.showStandardStreams = true - testLogging.exceptionFormat = 'full' - filter { - includeTestsMatching 'io.appium.java_client.android.SettingTest' - includeTestsMatching 'io.appium.java_client.android.ClipboardTest' - includeTestsMatching 'io.appium.java_client.android.OpenNotificationsTest' - includeTestsMatching '*.AndroidAppStringsTest' - includeTestsMatching '*.pagefactory_tests.widget.tests.android.*' - includeTestsMatching 'io.appium.java_client.service.local.StartingAppLocallyAndroidTest' - includeTestsMatching 'io.appium.java_client.service.local.ServerBuilderTest' - includeTestsMatching 'io.appium.java_client.service.local.ThreadSafetyTest' + targets.configureEach { + testTask.configure { + shouldRunAfter(test) + filter { + exclude '**/IOSScreenRecordTest.class' + exclude '**/ImagesComparisonTest.class' + } + } + } + } + + e2eAndroidTest(JvmTestSuite) { + sources { + java { + srcDirs = ['src/e2eAndroidTest/java'] + } + } + dependencies { + implementation project() + implementation(sourceSets.test.output) + implementation('io.github.bonigarcia:webdrivermanager:5.8.0') { + exclude group: 'org.seleniumhq.selenium' + } + } + + targets.configureEach { + testTask.configure { + shouldRunAfter(test) + filter { + // The following tests fail and should be reviewed/fixed + exclude '**/AndroidAbilityToUseSupplierTest.class' + exclude '**/AndroidConnectionTest.class' + exclude '**/AndroidContextTest.class' + exclude '**/AndroidDataMatcherTest.class' + exclude '**/AndroidDriverTest.class' + exclude '**/AndroidElementTest.class' + exclude '**/AndroidFunctionTest.class' + exclude '**/AndroidSearchingTest.class' + exclude '**/AndroidTouchTest.class' + exclude '**/AndroidViewMatcherTest.class' + exclude '**/ExecuteCDPCommandTest.class' + exclude '**/ExecuteDriverScriptTest.class' + exclude '**/FingerPrintTest.class' + exclude '**/ImagesComparisonTest.class' + exclude '**/KeyCodeTest.class' + exclude '**/LogEventTest.class' + exclude '**/UIAutomator2Test.class' + exclude '**/AndroidPageObjectTest.class' + exclude '**/MobileBrowserCompatibilityTest.class' + } + } + } + } } } diff --git a/gradle.properties b/gradle.properties index b67a7114b..44154a53b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ org.gradle.daemon=true selenium.version=4.19.0 # Please increment the value in a release -appiumClient.version=9.2.2 +appiumClient.version=9.2.3 diff --git a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidAppStringsTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidAppStringsTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidAppStringsTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidAppStringsTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidConnectionTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidConnectionTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidConnectionTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidContextTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidContextTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidContextTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidContextTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidDataMatcherTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidDataMatcherTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidDriverTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidDriverTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidDriverTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidElementTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidElementTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidElementTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidElementTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidFunctionTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidFunctionTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidFunctionTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidLogcatListenerTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidLogcatListenerTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidScreenRecordTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidScreenRecordTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidScreenRecordTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidScreenRecordTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidSearchingTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidSearchingTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidSearchingTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidTouchTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidTouchTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidTouchTest.java diff --git a/src/test/java/io/appium/java_client/android/AndroidViewMatcherTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/AndroidViewMatcherTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/AndroidViewMatcherTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/AndroidViewMatcherTest.java diff --git a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/BaseAndroidTest.java similarity index 94% rename from src/test/java/io/appium/java_client/android/BaseAndroidTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/BaseAndroidTest.java index e14343d75..347304cf5 100644 --- a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java +++ b/src/e2eAndroidTest/java/io/appium/java_client/android/BaseAndroidTest.java @@ -24,8 +24,6 @@ import java.util.Map; -import static io.appium.java_client.TestResources.apiDemosApk; - @SuppressWarnings("checkstyle:HideUtilityClassConstructor") public class BaseAndroidTest { public static final String APP_ID = "io.appium.android.apis"; @@ -46,7 +44,7 @@ public class BaseAndroidTest { UiAutomator2Options options = new UiAutomator2Options() .setDeviceName("Android Emulator") - .setApp(apiDemosApk().toAbsolutePath().toString()) + .setApp(TestResources.API_DEMOS_APK.toString()) .eventTimings(); driver = new AndroidDriver(service.getUrl(), options); } diff --git a/src/test/java/io/appium/java_client/android/BaseEspressoTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/BaseEspressoTest.java similarity index 93% rename from src/test/java/io/appium/java_client/android/BaseEspressoTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/BaseEspressoTest.java index d312587bd..f26469cb8 100644 --- a/src/test/java/io/appium/java_client/android/BaseEspressoTest.java +++ b/src/e2eAndroidTest/java/io/appium/java_client/android/BaseEspressoTest.java @@ -22,8 +22,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import static io.appium.java_client.TestResources.apiDemosApk; - @SuppressWarnings("checkstyle:HideUtilityClassConstructor") public class BaseEspressoTest { @@ -44,7 +42,7 @@ public class BaseEspressoTest { EspressoOptions options = new EspressoOptions() .setDeviceName("Android Emulator") - .setApp(apiDemosApk().toAbsolutePath().toString()) + .setApp(TestResources.API_DEMOS_APK.toString()) .eventTimings(); driver = new AndroidDriver(service.getUrl(), options); } diff --git a/src/test/java/io/appium/java_client/android/BatteryTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/BatteryTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/BatteryTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/BatteryTest.java diff --git a/src/test/java/io/appium/java_client/android/ClipboardTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/ClipboardTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/ClipboardTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/ClipboardTest.java diff --git a/src/test/java/io/appium/java_client/android/ExecuteCDPCommandTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/ExecuteCDPCommandTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/ExecuteCDPCommandTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/ExecuteCDPCommandTest.java diff --git a/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/ExecuteDriverScriptTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/ExecuteDriverScriptTest.java diff --git a/src/test/java/io/appium/java_client/android/FingerPrintTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/FingerPrintTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/FingerPrintTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/FingerPrintTest.java diff --git a/src/test/java/io/appium/java_client/android/ImagesComparisonTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/ImagesComparisonTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/ImagesComparisonTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/ImagesComparisonTest.java diff --git a/src/test/java/io/appium/java_client/android/KeyCodeTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/KeyCodeTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/KeyCodeTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/KeyCodeTest.java diff --git a/src/test/java/io/appium/java_client/android/LogEventTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/LogEventTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/LogEventTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/LogEventTest.java diff --git a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/OpenNotificationsTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/OpenNotificationsTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/OpenNotificationsTest.java diff --git a/src/test/java/io/appium/java_client/android/SettingTest.java b/src/e2eAndroidTest/java/io/appium/java_client/android/SettingTest.java similarity index 100% rename from src/test/java/io/appium/java_client/android/SettingTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/SettingTest.java diff --git a/src/e2eAndroidTest/java/io/appium/java_client/android/TestResources.java b/src/e2eAndroidTest/java/io/appium/java_client/android/TestResources.java new file mode 100644 index 000000000..149a72a4a --- /dev/null +++ b/src/e2eAndroidTest/java/io/appium/java_client/android/TestResources.java @@ -0,0 +1,12 @@ +package io.appium.java_client.android; + +import io.appium.java_client.TestUtils; + +import java.nio.file.Path; + +public class TestResources { + public static final Path API_DEMOS_APK = TestUtils.resourcePathToAbsolutePath("ApiDemos-debug.apk"); + + private TestResources() { + } +} diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/e2eAndroidTest/java/io/appium/java_client/android/UIAutomator2Test.java similarity index 100% rename from src/test/java/io/appium/java_client/android/UIAutomator2Test.java rename to src/e2eAndroidTest/java/io/appium/java_client/android/UIAutomator2Test.java diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java b/src/e2eAndroidTest/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java similarity index 100% rename from src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java b/src/e2eAndroidTest/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java similarity index 100% rename from src/test/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java diff --git a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java b/src/e2eAndroidTest/java/io/appium/java_client/service/local/ServerBuilderTest.java similarity index 92% rename from src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/service/local/ServerBuilderTest.java index 9822e9417..d482284b2 100644 --- a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java +++ b/src/e2eAndroidTest/java/io/appium/java_client/service/local/ServerBuilderTest.java @@ -1,5 +1,7 @@ package io.appium.java_client.service.local; +import io.appium.java_client.TestUtils; +import io.appium.java_client.android.TestResources; import io.appium.java_client.android.options.UiAutomator2Options; import io.github.bonigarcia.wdm.WebDriverManager; import org.junit.jupiter.api.AfterEach; @@ -15,7 +17,6 @@ import java.util.List; import java.util.Map; -import static io.appium.java_client.TestResources.apiDemosApk; import static io.appium.java_client.TestUtils.getLocalIp4Address; import static io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService; import static io.appium.java_client.service.local.AppiumServiceBuilder.APPIUM_PATH; @@ -27,7 +28,6 @@ import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; import static java.lang.System.getProperty; import static java.lang.System.setProperty; -import static java.nio.file.FileSystems.getDefault; import static java.util.Arrays.asList; import static java.util.Optional.ofNullable; import static java.util.concurrent.TimeUnit.SECONDS; @@ -49,14 +49,10 @@ class ServerBuilderTest { */ private static final String PATH_TO_APPIUM_NODE_IN_PROPERTIES = getProperty(APPIUM_PATH); - private static final Path ROOT_TEST_PATH = getDefault().getPath("src") - .resolve("test").resolve("java").resolve("io").resolve("appium").resolve("java_client"); - /** * This is the path to the stub main.js file */ - private static final Path PATH_T0_TEST_MAIN_JS = ROOT_TEST_PATH - .resolve("service").resolve("local").resolve("main.js"); + private static final Path PATH_T0_TEST_MAIN_JS = TestUtils.resourcePathToAbsolutePath("main.js"); private static String testIP; private AppiumDriverLocalService service; @@ -111,18 +107,14 @@ void checkAbilityToStartDefaultService() { @Test void checkAbilityToFindNodeDefinedInProperties() { - File definedNode = PATH_T0_TEST_MAIN_JS.toFile(); - setProperty(APPIUM_PATH, definedNode.getAbsolutePath()); - assertThat(new AppiumServiceBuilder().createArgs().get(0), is(definedNode.getAbsolutePath())); + setProperty(APPIUM_PATH, PATH_T0_TEST_MAIN_JS.toString()); + assertThat(new AppiumServiceBuilder().createArgs().get(0), is(PATH_T0_TEST_MAIN_JS.toString())); } @Test void checkAbilityToUseNodeDefinedExplicitly() { - File mainJS = PATH_T0_TEST_MAIN_JS.toFile(); - AppiumServiceBuilder builder = new AppiumServiceBuilder() - .withAppiumJS(mainJS); - assertThat(builder.createArgs().get(0), - is(mainJS.getAbsolutePath())); + AppiumServiceBuilder builder = new AppiumServiceBuilder().withAppiumJS(PATH_T0_TEST_MAIN_JS.toFile()); + assertThat(builder.createArgs().get(0), is(PATH_T0_TEST_MAIN_JS.toString())); } @Test @@ -156,7 +148,7 @@ void checkAbilityToStartServiceUsingCapabilities() { .setNewCommandTimeout(Duration.ofSeconds(60)) .setAppPackage("io.appium.android.apis") .setAppActivity(".view.WebView1") - .setApp(apiDemosApk().toAbsolutePath().toString()) + .setApp(TestResources.API_DEMOS_APK.toString()) .setChromedriverExecutable(chromeManager.getDownloadedDriverPath()); service = new AppiumServiceBuilder().withCapabilities(options).build(); @@ -166,14 +158,13 @@ void checkAbilityToStartServiceUsingCapabilities() { @Test void checkAbilityToStartServiceUsingCapabilitiesAndFlags() { - File app = ROOT_TEST_PATH.resolve("ApiDemos-debug.apk").toFile(); UiAutomator2Options options = new UiAutomator2Options() .fullReset() .setNewCommandTimeout(Duration.ofSeconds(60)) .setAppPackage("io.appium.android.apis") .setAppActivity(".view.WebView1") - .setApp(app.getAbsolutePath()) + .setApp(TestResources.API_DEMOS_APK.toString()) .setChromedriverExecutable(chromeManager.getDownloadedDriverPath()) .amend("winPath", "C:\\selenium\\app.apk") .amend("unixPath", "/selenium/app.apk") diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java b/src/e2eAndroidTest/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java similarity index 92% rename from src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java index 157077f88..77a7cc585 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java +++ b/src/e2eAndroidTest/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java @@ -17,6 +17,7 @@ package io.appium.java_client.service.local; import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.TestResources; import io.appium.java_client.android.options.UiAutomator2Options; import io.appium.java_client.remote.AutomationName; import io.appium.java_client.remote.MobilePlatform; @@ -27,7 +28,6 @@ import java.time.Duration; -import static io.appium.java_client.TestResources.apiDemosApk; import static io.appium.java_client.remote.options.SupportsAppOption.APP_OPTION; import static io.appium.java_client.remote.options.SupportsAutomationNameOption.AUTOMATION_NAME_OPTION; import static io.appium.java_client.remote.options.SupportsDeviceNameOption.DEVICE_NAME_OPTION; @@ -44,7 +44,7 @@ void startingAndroidAppWithCapabilitiesOnlyTest() { AndroidDriver driver = new AndroidDriver(new UiAutomator2Options() .setDeviceName("Android Emulator") .autoGrantPermissions() - .setApp(apiDemosApk().toAbsolutePath().toString())); + .setApp(TestResources.API_DEMOS_APK.toString())); try { Capabilities caps = driver.getCapabilities(); @@ -53,7 +53,7 @@ void startingAndroidAppWithCapabilitiesOnlyTest() { ); assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, caps.getCapability(AUTOMATION_NAME_OPTION)); assertNotNull(caps.getCapability(DEVICE_NAME_OPTION)); - assertEquals(apiDemosApk().toAbsolutePath().toString(), caps.getCapability(APP_OPTION)); + assertEquals(TestResources.API_DEMOS_APK.toString(), caps.getCapability(APP_OPTION)); } finally { driver.quit(); } @@ -68,7 +68,7 @@ void startingAndroidAppWithCapabilitiesAndServiceTest() { AndroidDriver driver = new AndroidDriver(builder, new UiAutomator2Options() .setDeviceName("Android Emulator") .autoGrantPermissions() - .setApp(apiDemosApk().toAbsolutePath().toString())); + .setApp(TestResources.API_DEMOS_APK.toString())); try { Capabilities caps = driver.getCapabilities(); @@ -88,7 +88,7 @@ void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() { .fullReset() .autoGrantPermissions() .setNewCommandTimeout(Duration.ofSeconds(60)) - .setApp(apiDemosApk().toAbsolutePath().toString()); + .setApp(TestResources.API_DEMOS_APK.toString()); WebDriverManager chromeManager = chromedriver(); chromeManager.setup(); diff --git a/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java b/src/e2eAndroidTest/java/io/appium/java_client/service/local/ThreadSafetyTest.java similarity index 100% rename from src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java rename to src/e2eAndroidTest/java/io/appium/java_client/service/local/ThreadSafetyTest.java diff --git a/src/test/resources/apps/ApiDemos-debug.apk b/src/e2eAndroidTest/resources/ApiDemos-debug.apk similarity index 100% rename from src/test/resources/apps/ApiDemos-debug.apk rename to src/e2eAndroidTest/resources/ApiDemos-debug.apk diff --git a/src/test/java/io/appium/java_client/service/local/main.js b/src/e2eAndroidTest/resources/main.js similarity index 100% rename from src/test/java/io/appium/java_client/service/local/main.js rename to src/e2eAndroidTest/resources/main.js diff --git a/src/test/java/io/appium/java_client/ios/AppIOSTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/AppIOSTest.java similarity index 73% rename from src/test/java/io/appium/java_client/ios/AppIOSTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/AppIOSTest.java index b049a15bb..25574d727 100644 --- a/src/test/java/io/appium/java_client/ios/AppIOSTest.java +++ b/src/e2eIosTest/java/io/appium/java_client/ios/AppIOSTest.java @@ -1,26 +1,26 @@ package io.appium.java_client.ios; +import io.appium.java_client.TestUtils; import io.appium.java_client.ios.options.XCUITestOptions; import org.junit.jupiter.api.BeforeAll; import org.openqa.selenium.SessionNotCreatedException; import java.time.Duration; -import static io.appium.java_client.TestResources.testAppZip; - public class AppIOSTest extends BaseIOSTest { + protected static final String BUNDLE_ID = "io.appium.TestApp"; - public static final String BUNDLE_ID = "io.appium.TestApp"; + private static final String TEST_APP_ZIP = TestUtils.resourcePathToAbsolutePath("TestApp.app.zip").toString(); @BeforeAll - public static void beforeClass() throws Exception { + public static void beforeClass() { startAppiumServer(); XCUITestOptions options = new XCUITestOptions() .setPlatformVersion(PLATFORM_VERSION) .setDeviceName(DEVICE_NAME) .setCommandTimeouts(Duration.ofSeconds(240)) - .setApp(testAppZip().toAbsolutePath().toString()) + .setApp(TEST_APP_ZIP) .setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT); try { driver = new IOSDriver(service.getUrl(), options); diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/BaseIOSTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/BaseIOSTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/BaseIOSTest.java diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/BaseIOSWebViewTest.java similarity index 92% rename from src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/BaseIOSWebViewTest.java index c461ded8a..f975d3c5b 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java +++ b/src/e2eIosTest/java/io/appium/java_client/ios/BaseIOSWebViewTest.java @@ -16,29 +16,29 @@ package io.appium.java_client.ios; +import io.appium.java_client.TestUtils; import io.appium.java_client.ios.options.XCUITestOptions; import org.junit.jupiter.api.BeforeAll; import org.openqa.selenium.SessionNotCreatedException; -import java.io.IOException; import java.time.Duration; import java.util.function.Supplier; -import static io.appium.java_client.TestResources.vodQaAppZip; - public class BaseIOSWebViewTest extends BaseIOSTest { + private static final String VODQA_ZIP = TestUtils.resourcePathToAbsolutePath("vodqa.zip").toString(); + private static final Duration WEB_VIEW_DETECT_INTERVAL = Duration.ofSeconds(1); private static final Duration WEB_VIEW_DETECT_DURATION = Duration.ofSeconds(15); @BeforeAll - public static void beforeClass() throws IOException { + public static void beforeClass() { startAppiumServer(); XCUITestOptions options = new XCUITestOptions() .setDeviceName(DEVICE_NAME) .setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT) .setCommandTimeouts(Duration.ofSeconds(240)) - .setApp(vodQaAppZip().toAbsolutePath().toString()); + .setApp(VODQA_ZIP); Supplier createDriver = () -> new IOSDriver(service.getUrl(), options); try { driver = createDriver.get(); diff --git a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/BaseSafariTest.java similarity index 88% rename from src/test/java/io/appium/java_client/ios/BaseSafariTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/BaseSafariTest.java index 654c4e58b..d35c76357 100644 --- a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java +++ b/src/e2eIosTest/java/io/appium/java_client/ios/BaseSafariTest.java @@ -21,8 +21,10 @@ import org.junit.jupiter.api.BeforeAll; import java.io.IOException; +import java.time.Duration; public class BaseSafariTest extends BaseIOSTest { + private static final Duration WEBVIEW_CONNECT_TIMEOUT = Duration.ofSeconds(30); @BeforeAll public static void beforeClass() throws IOException { startAppiumServer(); @@ -31,6 +33,7 @@ public class BaseSafariTest extends BaseIOSTest { .withBrowserName(MobileBrowserType.SAFARI) .setDeviceName(DEVICE_NAME) .setPlatformVersion(PLATFORM_VERSION) + .setWebviewConnectTimeout(WEBVIEW_CONNECT_TIMEOUT) .setWdaLaunchTimeout(WDA_LAUNCH_TIMEOUT); driver = new IOSDriver(service.getUrl(), options); } diff --git a/src/test/java/io/appium/java_client/ios/ClipboardTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/ClipboardTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/ClipboardTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/ClipboardTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSAlertTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSAlertTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSAlertTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSAppStringsTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSAppStringsTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSContextTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSContextTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSContextTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSContextTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSDriverTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSDriverTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSDriverTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSElementTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSElementTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSElementTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSScreenRecordTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSScreenRecordTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSScreenRecordTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSScreenRecordTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSSearchingTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSSearchingTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSSearchingTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSSyslogListenerTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSSyslogListenerTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSSyslogListenerTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSSyslogListenerTest.java diff --git a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/IOSWebViewTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/IOSWebViewTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/IOSWebViewTest.java diff --git a/src/test/java/io/appium/java_client/ios/ImagesComparisonTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/ImagesComparisonTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/ImagesComparisonTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/ImagesComparisonTest.java diff --git a/src/test/java/io/appium/java_client/ios/RotationTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/RotationTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/RotationTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/RotationTest.java diff --git a/src/test/java/io/appium/java_client/ios/SettingTest.java b/src/e2eIosTest/java/io/appium/java_client/ios/SettingTest.java similarity index 100% rename from src/test/java/io/appium/java_client/ios/SettingTest.java rename to src/e2eIosTest/java/io/appium/java_client/ios/SettingTest.java diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java b/src/e2eIosTest/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java similarity index 100% rename from src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java rename to src/e2eIosTest/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java b/src/e2eIosTest/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java similarity index 92% rename from src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java rename to src/e2eIosTest/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java index 5041231ec..b262e93af 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java +++ b/src/e2eIosTest/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java @@ -16,6 +16,7 @@ package io.appium.java_client.service.local; +import io.appium.java_client.TestUtils; import io.appium.java_client.ios.BaseIOSTest; import io.appium.java_client.ios.IOSDriver; import io.appium.java_client.ios.options.XCUITestOptions; @@ -26,7 +27,6 @@ import org.openqa.selenium.Capabilities; import org.openqa.selenium.Platform; -import static io.appium.java_client.TestResources.uiCatalogAppZip; import static io.appium.java_client.remote.options.SupportsDeviceNameOption.DEVICE_NAME_OPTION; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -35,12 +35,14 @@ import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; class StartingAppLocallyIosTest { + private static final String UI_CATALOG_ZIP = TestUtils.resourcePathToAbsolutePath("UICatalog.app.zip").toString(); + @Test void startingIOSAppWithCapabilitiesOnlyTest() { XCUITestOptions options = new XCUITestOptions() .setPlatformVersion(BaseIOSTest.PLATFORM_VERSION) .setDeviceName(BaseIOSTest.DEVICE_NAME) - .setApp(uiCatalogAppZip().toAbsolutePath().toString()) + .setApp(UI_CATALOG_ZIP) .setWdaLaunchTimeout(BaseIOSTest.WDA_LAUNCH_TIMEOUT); IOSDriver driver = new IOSDriver(options); try { @@ -50,7 +52,7 @@ void startingIOSAppWithCapabilitiesOnlyTest() { assertEquals(Platform.IOS, caps.getPlatformName()); assertNotNull(caps.getDeviceName().orElse(null)); assertEquals(BaseIOSTest.PLATFORM_VERSION, caps.getPlatformVersion().orElse(null)); - assertEquals(uiCatalogAppZip().toAbsolutePath().toString(), caps.getApp().orElse(null)); + assertEquals(UI_CATALOG_ZIP, caps.getApp().orElse(null)); } finally { driver.quit(); } @@ -62,7 +64,7 @@ void startingIOSAppWithCapabilitiesAndServiceTest() { XCUITestOptions options = new XCUITestOptions() .setPlatformVersion(BaseIOSTest.PLATFORM_VERSION) .setDeviceName(BaseIOSTest.DEVICE_NAME) - .setApp(uiCatalogAppZip().toAbsolutePath().toString()) + .setApp(UI_CATALOG_ZIP) .setWdaLaunchTimeout(BaseIOSTest.WDA_LAUNCH_TIMEOUT); AppiumServiceBuilder builder = new AppiumServiceBuilder() @@ -89,7 +91,7 @@ void startingIOSAppWithCapabilitiesAndFlagsOnServerSideTest() { .setWdaLaunchTimeout(BaseIOSTest.WDA_LAUNCH_TIMEOUT); XCUITestOptions clientOptions = new XCUITestOptions() - .setApp(uiCatalogAppZip().toAbsolutePath().toString()); + .setApp(UI_CATALOG_ZIP); AppiumServiceBuilder builder = new AppiumServiceBuilder() .withArgument(GeneralServerFlag.SESSION_OVERRIDE) diff --git a/src/test/resources/apps/TestApp.app.zip b/src/e2eIosTest/resources/TestApp.app.zip similarity index 100% rename from src/test/resources/apps/TestApp.app.zip rename to src/e2eIosTest/resources/TestApp.app.zip diff --git a/src/test/resources/apps/UICatalog.app.zip b/src/e2eIosTest/resources/UICatalog.app.zip similarity index 100% rename from src/test/resources/apps/UICatalog.app.zip rename to src/e2eIosTest/resources/UICatalog.app.zip diff --git a/src/test/resources/apps/vodqa.zip b/src/e2eIosTest/resources/vodqa.zip similarity index 100% rename from src/test/resources/apps/vodqa.zip rename to src/e2eIosTest/resources/vodqa.zip diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 6d66639c9..c8d660e9f 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -20,7 +20,6 @@ import io.appium.java_client.internal.ReflectionHelpers; import io.appium.java_client.internal.SessionHelpers; import io.appium.java_client.remote.AppiumCommandExecutor; -import io.appium.java_client.remote.AppiumNewSessionCommandPayload; import io.appium.java_client.remote.AppiumW3CHttpCommandCodec; import io.appium.java_client.remote.options.BaseOptions; import io.appium.java_client.service.local.AppiumDriverLocalService; @@ -50,11 +49,13 @@ import java.util.Collections; import java.util.HashSet; import java.util.Map; +import java.util.Optional; import java.util.Set; import static com.google.common.base.Strings.isNullOrEmpty; import static io.appium.java_client.internal.CapabilityHelpers.APPIUM_PREFIX; import static io.appium.java_client.remote.options.SupportsAutomationNameOption.AUTOMATION_NAME_OPTION; +import static java.util.Collections.singleton; import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; /** @@ -265,25 +266,27 @@ public void addCommand(HttpMethod httpMethod, String url, String methodName) { @Override protected void startSession(Capabilities capabilities) { - Response response = execute(new AppiumNewSessionCommandPayload(capabilities)); - if (response == null) { - throw new SessionNotCreatedException( - "The underlying command executor returned a null response."); - } - - Object responseValue = response.getValue(); - if (responseValue == null) { - throw new SessionNotCreatedException( - "The underlying command executor returned a response without payload: " - + response); - } - if (!(responseValue instanceof Map)) { - throw new SessionNotCreatedException( - "The underlying command executor returned a response with a non well formed payload: " - + response); - } + var response = Optional.ofNullable( + execute(DriverCommand.NEW_SESSION(singleton(capabilities))) + ).orElseThrow(() -> new SessionNotCreatedException( + "The underlying command executor returned a null response." + )); + + var rawCapabilities = Optional.ofNullable(response.getValue()) + .map(value -> { + if (!(value instanceof Map)) { + throw new SessionNotCreatedException(String.format( + "The underlying command executor returned a response " + + "with a non well formed payload: %s", response) + ); + } + //noinspection unchecked + return (Map) value; + }) + .orElseThrow(() -> new SessionNotCreatedException( + "The underlying command executor returned a response without payload: " + response) + ); - @SuppressWarnings("unchecked") Map rawCapabilities = (Map) responseValue; // TODO: remove this workaround for Selenium API enforcing some legacy capability values in major version rawCapabilities.remove("platform"); if (rawCapabilities.containsKey(CapabilityType.BROWSER_NAME) diff --git a/src/main/java/io/appium/java_client/ComparesImages.java b/src/main/java/io/appium/java_client/ComparesImages.java index 1b29c35cf..5a9a58b1c 100644 --- a/src/main/java/io/appium/java_client/ComparesImages.java +++ b/src/main/java/io/appium/java_client/ComparesImages.java @@ -126,8 +126,7 @@ default OccurrenceMatchingResult findImageOccurrence(byte[] fullImage, byte[] pa @Nullable OccurrenceMatchingOptions options) { Object response = CommandExecutionHelper.execute(this, compareImagesCommand(ComparisonMode.MATCH_TEMPLATE, fullImage, partialImage, options)); - //noinspection unchecked - return new OccurrenceMatchingResult((Map) response); + return new OccurrenceMatchingResult(response); } /** diff --git a/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java b/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java index 447377633..3c42f5c35 100644 --- a/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java +++ b/src/main/java/io/appium/java_client/android/CanReplaceElementValue.java @@ -21,7 +21,7 @@ public interface CanReplaceElementValue extends ExecutesMethod, CanRememberExten * off from the typed text). */ default void replaceElementValue(RemoteWebElement element, String value) { - final String extName = "mobile: replaceValue"; + final String extName = "mobile: replaceElementValue"; try { CommandExecutionHelper.executeScript(assertExtensionExists(extName), extName, Map.of( "elementId", element.getId(), 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 49e487b59..0fba408d4 100644 --- a/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java +++ b/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java @@ -16,8 +16,6 @@ package io.appium.java_client.imagecomparison; -import lombok.AccessLevel; -import lombok.Getter; import org.openqa.selenium.Point; import org.openqa.selenium.Rectangle; @@ -32,12 +30,17 @@ public abstract class ComparisonResult { private static final String VISUALIZATION = "visualization"; - @Getter(AccessLevel.PROTECTED) private final Map commandResult; + protected final Object commandResult; - public ComparisonResult(Map commandResult) { + public ComparisonResult(Object commandResult) { this.commandResult = commandResult; } + protected Map getResultAsMap() { + //noinspection unchecked + return (Map) commandResult; + } + /** * Verifies if the corresponding property is present in the commend result * and throws an exception if not. @@ -45,7 +48,7 @@ public ComparisonResult(Map commandResult) { * @param propertyName the actual property name to be verified for presence */ protected void verifyPropertyPresence(String propertyName) { - if (!commandResult.containsKey(propertyName)) { + if (!getResultAsMap().containsKey(propertyName)) { throw new IllegalStateException( String.format("There is no '%s' attribute in the resulting command output %s. " + "Did you set the options properly?", propertyName, commandResult)); @@ -59,13 +62,13 @@ protected void verifyPropertyPresence(String propertyName) { */ public byte[] getVisualization() { verifyPropertyPresence(VISUALIZATION); - return ((String) getCommandResult().get(VISUALIZATION)).getBytes(StandardCharsets.UTF_8); + return ((String) getResultAsMap().get(VISUALIZATION)).getBytes(StandardCharsets.UTF_8); } /** * Stores visualization image into the given file. * - * @param destination file to save image. + * @param destination File path to save the image to. * @throws IOException On file system I/O error. */ public void storeVisualization(File destination) throws IOException { diff --git a/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java b/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java index 2ba90c7dd..0a983e50a 100644 --- a/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java +++ b/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java @@ -43,7 +43,7 @@ public FeaturesMatchingResult(Map input) { */ public int getCount() { verifyPropertyPresence(COUNT); - return ((Long) getCommandResult().get(COUNT)).intValue(); + return ((Long) getResultAsMap().get(COUNT)).intValue(); } /** @@ -56,7 +56,7 @@ public int getCount() { */ public int getTotalCount() { verifyPropertyPresence(TOTAL_COUNT); - return ((Long) getCommandResult().get(TOTAL_COUNT)).intValue(); + return ((Long) getResultAsMap().get(TOTAL_COUNT)).intValue(); } /** @@ -67,7 +67,7 @@ public int getTotalCount() { public List getPoints1() { verifyPropertyPresence(POINTS1); //noinspection unchecked - return ((List>) getCommandResult().get(POINTS1)).stream() + return ((List>) getResultAsMap().get(POINTS1)).stream() .map(ComparisonResult::mapToPoint) .collect(Collectors.toList()); } @@ -80,7 +80,7 @@ public List getPoints1() { public Rectangle getRect1() { verifyPropertyPresence(RECT1); //noinspection unchecked - return mapToRect((Map) getCommandResult().get(RECT1)); + return mapToRect((Map) getResultAsMap().get(RECT1)); } /** @@ -91,7 +91,7 @@ public Rectangle getRect1() { public List getPoints2() { verifyPropertyPresence(POINTS2); //noinspection unchecked - return ((List>) getCommandResult().get(POINTS2)).stream() + return ((List>) getResultAsMap().get(POINTS2)).stream() .map(ComparisonResult::mapToPoint) .collect(Collectors.toList()); } @@ -104,6 +104,6 @@ public List getPoints2() { public Rectangle getRect2() { verifyPropertyPresence(RECT2); //noinspection unchecked - return mapToRect((Map) getCommandResult().get(RECT2)); + return mapToRect((Map) getResultAsMap().get(RECT2)); } } diff --git a/src/main/java/io/appium/java_client/imagecomparison/OccurrenceMatchingResult.java b/src/main/java/io/appium/java_client/imagecomparison/OccurrenceMatchingResult.java index 510f64b8e..7b0266f23 100644 --- a/src/main/java/io/appium/java_client/imagecomparison/OccurrenceMatchingResult.java +++ b/src/main/java/io/appium/java_client/imagecomparison/OccurrenceMatchingResult.java @@ -18,34 +18,131 @@ import org.openqa.selenium.Rectangle; +import java.io.File; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class OccurrenceMatchingResult extends ComparisonResult { private static final String RECT = "rect"; - private static final String MULTIPLE = "multiple"; + private static final String SCORE = "score"; - private final boolean isAtRoot; + private final boolean hasMultiple; - public OccurrenceMatchingResult(Map input) { - this(input, true); + public OccurrenceMatchingResult(Object input) { + super(input); + hasMultiple = input instanceof List; } - private OccurrenceMatchingResult(Map input, boolean isAtRoot) { - super(input); - this.isAtRoot = isAtRoot; + /** + * Check whether the current instance contains multiple matches. + * + * @return True or false. + */ + public boolean hasMultiple() { + return hasMultiple; } /** - * Returns rectangle of partial image occurrence. + * Returns rectangle of the partial image occurrence. * * @return The region of the partial image occurrence on the full image. */ public Rectangle getRect() { + if (hasMultiple) { + return getRect(0); + } verifyPropertyPresence(RECT); //noinspection unchecked - return mapToRect((Map) getCommandResult().get(RECT)); + return mapToRect((Map) getResultAsMap().get(RECT)); + } + + /** + * Returns rectangle of the partial image occurrence for the given match index. + * + * @param matchIndex Match index. + * @return Matching rectangle. + * @throws IllegalStateException If the current instance does not represent multiple matches. + */ + public Rectangle getRect(int matchIndex) { + return getMatch(matchIndex).getRect(); + } + + /** + * Returns the score of the partial image occurrence. + * + * @return Matching score in range 0..1. + */ + public double getScore() { + if (hasMultiple) { + return getScore(0); + } + verifyPropertyPresence(SCORE); + var value = getResultAsMap().get(SCORE); + if (value instanceof Long) { + return ((Long) value).doubleValue(); + } + return (Double) value; + } + + /** + * Returns the score of the partial image occurrence for the given match index. + * + * @param matchIndex Match index. + * @return Matching score in range 0..1. + * @throws IllegalStateException If the current instance does not represent multiple matches. + */ + public double getScore(int matchIndex) { + return getMatch(matchIndex).getScore(); + } + + /** + * Returns the visualization of the matching result. + * + * @return The visualization of the matching result represented as base64-encoded PNG image. + */ + @Override + public byte[] getVisualization() { + return hasMultiple ? getVisualization(0) : super.getVisualization(); + } + + /** + * Returns the visualization of the partial image occurrence for the given match index. + * + * @param matchIndex Match index. + * @return The visualization of the matching result represented as base64-encoded PNG image. + * @throws IllegalStateException If the current instance does not represent multiple matches. + */ + public byte[] getVisualization(int matchIndex) { + return getMatch(matchIndex).getVisualization(); + } + + /** + * Stores visualization image into the given file. + * + * @param destination File path to save the image to. + * @throws IOException On file system I/O error. + */ + @Override + public void storeVisualization(File destination) throws IOException { + if (hasMultiple) { + getMatch(0).storeVisualization(destination); + } else { + super.storeVisualization(destination); + } + } + + /** + * Stores visualization image into the given file. + * + * @param matchIndex Match index. + * @param destination File path to save the image to. + * @throws IOException On file system I/O error. + * @throws IllegalStateException If the current instance does not represent multiple matches. + */ + public void storeVisualization(int matchIndex, File destination) throws IOException { + getMatch(matchIndex).storeVisualization(destination); } /** @@ -54,18 +151,37 @@ public Rectangle getRect() { * * @since Appium 1.21.0 * @return The list containing properties of each single match or an empty list. - * @throws IllegalStateException If the accessor is called on a non-root match instance. + * @throws IllegalStateException If the current instance does not represent multiple matches. */ public List getMultiple() { - if (!isAtRoot) { - throw new IllegalStateException("Only the root match could contain multiple submatches"); - } - verifyPropertyPresence(MULTIPLE); + return getMultipleMatches(false); + } + private List getMultipleMatches(boolean throwIfEmpty) { + if (!hasMultiple) { + throw new IllegalStateException(String.format( + "This %s does not represent multiple matches. Did you set options properly?", + getClass().getSimpleName() + )); + } //noinspection unchecked - List> multiple = (List>) getCommandResult().get(MULTIPLE); - return multiple.stream() - .map(m -> new OccurrenceMatchingResult(m, false)) + var matches = ((List>) commandResult).stream() + .map(OccurrenceMatchingResult::new) .collect(Collectors.toList()); + if (matches.isEmpty() && throwIfEmpty) { + throw new IllegalStateException("Zero matches have been found. Try the lookup with different options."); + } + return matches; + } + + private OccurrenceMatchingResult getMatch(int index) { + var matches = getMultipleMatches(true); + if (index < 0 || index >= matches.size()) { + throw new IndexOutOfBoundsException(String.format( + "The match #%s does not exist. The total number of found matches is %s", + index, matches.size() + )); + } + return matches.get(index); } } diff --git a/src/main/java/io/appium/java_client/imagecomparison/SimilarityMatchingResult.java b/src/main/java/io/appium/java_client/imagecomparison/SimilarityMatchingResult.java index 50c388ead..0806e7b53 100644 --- a/src/main/java/io/appium/java_client/imagecomparison/SimilarityMatchingResult.java +++ b/src/main/java/io/appium/java_client/imagecomparison/SimilarityMatchingResult.java @@ -33,10 +33,9 @@ public SimilarityMatchingResult(Map input) { */ public double getScore() { verifyPropertyPresence(SCORE); - //noinspection unchecked - if (getCommandResult().get(SCORE) instanceof Long) { - return ((Long) getCommandResult().get(SCORE)).doubleValue(); + if (getResultAsMap().get(SCORE) instanceof Long) { + return ((Long) getResultAsMap().get(SCORE)).doubleValue(); } - return (double) getCommandResult().get(SCORE); + return (double) getResultAsMap().get(SCORE); } } diff --git a/src/main/java/io/appium/java_client/internal/filters/AppiumUserAgentFilter.java b/src/main/java/io/appium/java_client/internal/filters/AppiumUserAgentFilter.java index 7c68cfad1..d4f1842ce 100644 --- a/src/main/java/io/appium/java_client/internal/filters/AppiumUserAgentFilter.java +++ b/src/main/java/io/appium/java_client/internal/filters/AppiumUserAgentFilter.java @@ -16,11 +16,11 @@ package io.appium.java_client.internal.filters; -import com.google.common.net.HttpHeaders; import io.appium.java_client.internal.Config; import org.openqa.selenium.remote.http.AddSeleniumUserAgent; import org.openqa.selenium.remote.http.Filter; import org.openqa.selenium.remote.http.HttpHandler; +import org.openqa.selenium.remote.http.HttpHeader; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -81,7 +81,9 @@ public static String buildUserAgent(@Nullable String userAgent) { @Override public HttpHandler apply(HttpHandler next) { return req -> { - req.setHeader(HttpHeaders.USER_AGENT, buildUserAgent(req.getHeader(HttpHeaders.USER_AGENT))); + var originalUserAgentHeader = req.getHeader(HttpHeader.UserAgent.getName()); + var newUserAgentHeader = buildUserAgent(originalUserAgentHeader); + req.setHeader(HttpHeader.UserAgent.getName(), newUserAgentHeader); return next.execute(req); }; } diff --git a/src/main/java/io/appium/java_client/proxy/Helpers.java b/src/main/java/io/appium/java_client/proxy/Helpers.java index af724ae43..d162c3ed5 100644 --- a/src/main/java/io/appium/java_client/proxy/Helpers.java +++ b/src/main/java/io/appium/java_client/proxy/Helpers.java @@ -136,7 +136,7 @@ public static T createProxy( .defineField("methodCallListeners", MethodCallListener[].class, Visibility.PRIVATE) .implement(HasMethodCallListeners.class).intercept(FieldAccessor.ofBeanProperty()) .make() - .load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.WRAPPER) + .load(Helpers.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER) .getLoaded() .asSubclass(cls); }); 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 d3310f478..118f0ff81 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java +++ b/src/main/java/io/appium/java_client/remote/AppiumCommandExecutor.java @@ -173,7 +173,7 @@ private Response createSession(Command command) throws IOException { throw new SessionNotCreatedException("Session already exists"); } - ProtocolHandshake.Result result = new AppiumProtocolHandshake().createSession(getClient(), command); + var result = new ProtocolHandshake().createSession(getClient(), command); Dialect dialect = result.getDialect(); if (!(dialect.getCommandCodec() instanceof W3CHttpCommandCodec)) { throw new SessionNotCreatedException("Only W3C sessions are supported. " diff --git a/src/main/java/io/appium/java_client/remote/AppiumNewSessionCommandPayload.java b/src/main/java/io/appium/java_client/remote/AppiumNewSessionCommandPayload.java index 63fc663a5..31635dabb 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumNewSessionCommandPayload.java +++ b/src/main/java/io/appium/java_client/remote/AppiumNewSessionCommandPayload.java @@ -27,6 +27,12 @@ import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION; +/** + * This class is deprecated and will be removed. + * + * @deprecated Use CommandPayload instead. + */ +@Deprecated public class AppiumNewSessionCommandPayload extends CommandPayload { /** * Appends "appium:" prefix to all non-prefixed non-standard capabilities. diff --git a/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java b/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java index f92a3632d..ef2f659da 100644 --- a/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java +++ b/src/main/java/io/appium/java_client/remote/AppiumProtocolHandshake.java @@ -16,108 +16,13 @@ package io.appium.java_client.remote; -import org.openqa.selenium.Capabilities; -import org.openqa.selenium.ImmutableCapabilities; -import org.openqa.selenium.SessionNotCreatedException; -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.internal.Either; -import org.openqa.selenium.json.Json; -import org.openqa.selenium.json.JsonOutput; -import org.openqa.selenium.remote.Command; -import org.openqa.selenium.remote.NewSessionPayload; import org.openqa.selenium.remote.ProtocolHandshake; -import org.openqa.selenium.remote.http.Contents; -import org.openqa.selenium.remote.http.HttpHandler; -import java.io.IOException; -import java.io.StringWriter; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Set; -import java.util.stream.Stream; - -@SuppressWarnings("UnstableApiUsage") +/** + * This class is deprecated and should be removed. + * + * @deprecated Use ProtocolHandshake instead. + */ +@Deprecated public class AppiumProtocolHandshake extends ProtocolHandshake { - private static void writeJsonPayload(NewSessionPayload srcPayload, Appendable destination) { - try (JsonOutput json = new Json().newOutput(destination)) { - json.beginObject(); - - json.name("capabilities"); - json.beginObject(); - - json.name("firstMatch"); - json.beginArray(); - json.beginObject(); - json.endObject(); - json.endArray(); - - json.name("alwaysMatch"); - try { - Method getW3CMethod = NewSessionPayload.class.getDeclaredMethod("getW3C"); - getW3CMethod.setAccessible(true); - //noinspection unchecked,resource - ((Stream>) getW3CMethod.invoke(srcPayload)) - .findFirst() - .map(json::write) - .orElseGet(() -> { - json.beginObject(); - json.endObject(); - return null; - }); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - throw new WebDriverException(e); - } - - json.endObject(); // Close "capabilities" object - - try { - Method writeMetaDataMethod = NewSessionPayload.class.getDeclaredMethod( - "writeMetaData", JsonOutput.class); - writeMetaDataMethod.setAccessible(true); - writeMetaDataMethod.invoke(srcPayload, json); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - throw new WebDriverException(e); - } - - json.endObject(); - } - } - - @Override - public Result createSession(HttpHandler client, Command command) throws IOException { - //noinspection unchecked - Capabilities desired = ((Set>) command.getParameters().get("capabilities")) - .stream() - .findAny() - .map(ImmutableCapabilities::new) - .orElseGet(ImmutableCapabilities::new); - try (NewSessionPayload payload = NewSessionPayload.create(desired)) { - Either result = createSession(client, payload); - if (result.isRight()) { - return result.right(); - } - throw result.left(); - } - } - - @Override - public Either createSession(HttpHandler client, NewSessionPayload payload) { - - StringWriter stringWriter = new StringWriter(); - writeJsonPayload(payload, stringWriter); - - try { - Method createSessionMethod = ProtocolHandshake.class.getDeclaredMethod( - "createSession", HttpHandler.class, Contents.Supplier.class - ); - createSessionMethod.setAccessible(true); - //noinspection unchecked - return (Either) createSessionMethod.invoke( - this, client, Contents.utf8String(stringWriter.toString()) - ); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - throw new WebDriverException(e); - } - } } diff --git a/src/test/java/io/appium/java_client/TestResources.java b/src/test/java/io/appium/java_client/TestResources.java deleted file mode 100644 index 6928cdcaf..000000000 --- a/src/test/java/io/appium/java_client/TestResources.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.appium.java_client; - -import java.nio.file.Path; - -import static io.appium.java_client.TestUtils.resourcePathToLocalPath; - -public class TestResources { - private TestResources() { - } - - public static Path apiDemosApk() { - return resourcePathToLocalPath("apps/ApiDemos-debug.apk"); - } - - public static Path testAppZip() { - return resourcePathToLocalPath("apps/TestApp.app.zip"); - } - - public static Path uiCatalogAppZip() { - return resourcePathToLocalPath("apps/UICatalog.app.zip"); - } - - public static Path vodQaAppZip() { - return resourcePathToLocalPath("apps/vodqa.zip"); - } - - public static Path intentExampleApk() { - return resourcePathToLocalPath("apps/IntentExample.apk"); - } - - public static Path helloAppiumHtml() { - return resourcePathToLocalPath("html/hello appium - saved page.htm"); - } -} diff --git a/src/test/java/io/appium/java_client/TestUtils.java b/src/test/java/io/appium/java_client/TestUtils.java index aaf254f75..1d650777c 100644 --- a/src/test/java/io/appium/java_client/TestUtils.java +++ b/src/test/java/io/appium/java_client/TestUtils.java @@ -6,14 +6,12 @@ import org.openqa.selenium.WebElement; import javax.annotation.Nullable; -import java.io.IOException; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.URISyntaxException; import java.net.URL; import java.net.UnknownHostException; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; @@ -31,26 +29,18 @@ public static String getLocalIp4Address() throws SocketException, UnknownHostExc } } - public static Path resourcePathToLocalPath(String resourcePath) { + public static Path resourcePathToAbsolutePath(String resourcePath) { URL url = ClassLoader.getSystemResource(resourcePath); if (url == null) { throw new IllegalArgumentException(String.format("Cannot find the '%s' resource", resourcePath)); } try { - return Paths.get(url.toURI()); + return Paths.get(url.toURI()).toAbsolutePath(); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } - public static String resourceAsString(String resourcePath) { - try { - return new String(Files.readAllBytes(resourcePathToLocalPath(resourcePath))); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - public static void waitUntilTrue(Supplier func, Duration timeout, Duration interval) { long started = System.currentTimeMillis(); RuntimeException lastError = null; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java index 0a890dc67..40c672ae7 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java @@ -16,6 +16,7 @@ package io.appium.java_client.pagefactory_tests; +import io.appium.java_client.TestUtils; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AndroidFindBy; import io.appium.java_client.pagefactory.AppiumFieldDecorator; @@ -33,7 +34,6 @@ import java.util.List; -import static io.appium.java_client.TestResources.helloAppiumHtml; import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE; import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; import static java.time.Duration.ofSeconds; @@ -41,6 +41,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; public class DesktopBrowserCompatibilityTest { + private static final String HELLO_APPIUM_HTML = + TestUtils.resourcePathToAbsolutePath("html/hello appium - saved page.htm").toUri().toString(); @HowToUseLocators(iOSXCUITAutomation = ALL_POSSIBLE) @AndroidFindBy(className = "someClass") @@ -62,7 +64,7 @@ public class DesktopBrowserCompatibilityTest { WebDriver driver = new ChromeDriver(new ChromeOptions().addArguments("--headless=new")); try { PageFactory.initElements(new AppiumFieldDecorator(driver, ofSeconds(15)), this); - driver.get(helloAppiumHtml().toUri().toString()); + driver.get(HELLO_APPIUM_HTML); assertNotEquals(0, foundLinks.size()); assertNotEquals(0, main.size()); assertNull(trap1); diff --git a/src/test/resources/apps/IntentExample.apk b/src/test/resources/apps/IntentExample.apk deleted file mode 100644 index 196ea9094..000000000 Binary files a/src/test/resources/apps/IntentExample.apk and /dev/null differ