From 0d0b85464b980a5c0e618865a94b38c4b2ec2f90 Mon Sep 17 00:00:00 2001 From: Valery Yatsynovich Date: Fri, 12 May 2023 10:21:31 +0300 Subject: [PATCH] ci: Move execution of E2E tests to GitHub Actions --- .azure-templates/bootstrap_steps.yml | 10 -- .github/workflows/gradle.yml | 97 ++++++++++++++++++- azure-pipelines.yml | 69 ------------- .../appium/java_client/ios/BaseIOSTest.java | 1 + 4 files changed, 94 insertions(+), 83 deletions(-) delete mode 100644 .azure-templates/bootstrap_steps.yml delete mode 100644 azure-pipelines.yml diff --git a/.azure-templates/bootstrap_steps.yml b/.azure-templates/bootstrap_steps.yml deleted file mode 100644 index baf4b6979..000000000 --- a/.azure-templates/bootstrap_steps.yml +++ /dev/null @@ -1,10 +0,0 @@ -steps: - - task: NodeTool@0 - inputs: - versionSpec: "$(NODE_VERSION)" - - script: | - npm config delete prefix - npm config set prefix $NVM_DIR/versions/node/`node --version` - node --version - - npm install -g appium@next diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index cd399065c..872468fad 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -14,23 +14,112 @@ on: - 'docs/**' - '*.md' +env: + ANDROID_SDK_VERSION: 28 + ANDROID_EMU_NAME: test + XCODE_VERSION: 14.2 + IOS_DEVICE_NAME: iPhone 12 + IOS_PLATFORM_VERSION: 16.2 + jobs: build: - runs-on: macOS-latest - strategy: matrix: - java: [ 8, 11, 17 ] + include: + # TODO: add new LTS Java ( 21 ) once it's released + - java: 8 + platform: macos-latest + e2e-tests: android + - java: 11 + # Need to use specific (not `-latest`) version of macOS to be sure the required version of Xcode/simulator is available + platform: macos-12 + e2e-tests: ios + - java: 17 + platform: ubuntu-latest + fail-fast: false + + runs-on: ${{ matrix.platform }} - name: JDK ${{ matrix.java }} + name: JDK ${{ matrix.java }} - ${{ matrix.platform }} steps: - uses: actions/checkout@v3 + - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@v3 with: distribution: 'zulu' java-version: ${{ matrix.java }} cache: 'gradle' + - name: Build with Gradle run: ./gradlew clean build + + - name: Install Node.js + if: ${{ matrix.e2e-tests == 'android' || matrix.e2e-tests == 'ios' }} + uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + + - name: Install Appium + if: matrix.e2e-tests == 'android' || matrix.e2e-tests == 'ios' + run: npm install -g appium@next + + - name: Install UIA2 driver + if: matrix.e2e-tests == 'android' + run: appium driver install uiautomator2 + + - name: AVD cache + if: matrix.e2e-tests == 'android' + uses: actions/cache@v3 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-${{ env.ANDROID_SDK_VERSION }} + + - name: Generate AVD snapshot for caching + if: matrix.e2e-tests == 'android' && steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ env.ANDROID_SDK_VERSION }} + avd-name: ${{ env.ANDROID_EMU_NAME }} + force-avd-creation: false + script: echo "Generated AVD snapshot for caching." + + - name: Run Android E2E tests + if: matrix.e2e-tests == 'android' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ env.ANDROID_SDK_VERSION }} + avd-name: ${{ env.ANDROID_EMU_NAME }} + force-avd-creation: false + emulator-options: -no-snapshot -delay-adb + script: ./gradlew uiAutomationTest + + - name: Select Xcode + if: matrix.e2e-tests == 'ios' + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: "${{ env.XCODE_VERSION }}" + + - name: Install XCUITest driver + if: matrix.e2e-tests == 'ios' + run: appium driver install xcuitest + + - name: Prebuild XCUITest driver + if: matrix.e2e-tests == 'ios' + run: appium driver run xcuitest build-wda + + - name: Prepare iOS simulator + if: matrix.e2e-tests == 'ios' + run: | + xcrun simctl list + target_sim_id=$(xcrun simctl list devices available | grep "$IOS_DEVICE_NAME (" | cut -d "(" -f2 | cut -d ")" -f1) + open -Fn "/Applications/Xcode_$XCODE_VERSION.app/Contents/Developer/Applications/Simulator.app" + xcrun simctl bootstatus $target_sim_id -b + + - name: Run iOS E2E tests + if: matrix.e2e-tests == 'ios' + run: ./gradlew xcuiTest diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 4cea8df6d..000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,69 +0,0 @@ -# Gradle -# Build your Java project and run tests with Gradle using a Gradle wrapper script. -# Add steps that analyze code, save build artifacts, deploy, and more: -# https://docs.microsoft.com/azure/devops/pipelines/languages/java - -pool: - vmImage: 'macos-12' - -variables: - ANDROID_EMU_NAME: test - ANDROID_EMU_ABI: x86 - ANDROID_EMU_TARGET: android-28 - ANDROID_EMU_TAG: default - XCODE_VERSION: 14.2 - IOS_PLATFORM_VERSION: 16.2 - IOS_DEVICE_NAME: iPhone 12 - NODE_VERSION: 18.x - JDK_VERSION: 1.8 - -jobs: -- job: Android_E2E_Tests - steps: - - template: .azure-templates/bootstrap_steps.yml - - script: $NVM_DIR/versions/node/`node --version`/bin/appium driver install uiautomator2 - displayName: Install UIA2 driver - - script: | - 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" - nohup $ANDROID_HOME/emulator/emulator -avd "$(ANDROID_EMU_NAME)" -no-snapshot -delay-adb > /dev/null 2>&1 & - $ANDROID_HOME/platform-tools/adb wait-for-device - $ANDROID_HOME/platform-tools/adb devices -l - echo "Emulator started" - displayName: Emulator configuration - - task: Gradle@2 - inputs: - gradleWrapperFile: 'gradlew' - gradleOptions: '-Xmx3072m' - javaHomeOption: 'JDKVersion' - jdkVersionOption: "$(JDK_VERSION)" - jdkArchitectureOption: 'x64' - publishJUnitResults: true - tasks: 'build uiAutomationTest' -- job: iOS_E2E_Tests -# timeoutInMinutes: '90' - steps: - - template: .azure-templates/bootstrap_steps.yml - - script: | - sudo xcode-select -s /Applications/Xcode_$(XCODE_VERSION).app/Contents/Developer - xcrun simctl list - target_sim_id=$(xcrun simctl list devices available | grep "$IOS_DEVICE_NAME (" | cut -d "(" -f2 | cut -d ")" -f1) - open -Fn "/Applications/Xcode_$(XCODE_VERSION).app/Contents/Developer/Applications/Simulator.app" - xcrun simctl bootstatus $target_sim_id -b - displayName: Prepare iOS Simulator - - script: $NVM_DIR/versions/node/$(node --version)/bin/appium driver install xcuitest - displayName: Install XCUITest driver - - script: $NVM_DIR/versions/node/$(node --version)/bin/appium driver run xcuitest build-wda - displayName: Prebuild XCUITest driver - - task: Gradle@2 - inputs: - gradleWrapperFile: 'gradlew' - gradleOptions: '-Xmx3072m' - javaHomeOption: 'JDKVersion' - jdkVersionOption: "$(JDK_VERSION)" - jdkArchitectureOption: 'x64' - publishJUnitResults: true - tasks: 'build xcuiTest' 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 dfdf3c4da..1661e19c9 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java @@ -44,6 +44,7 @@ public static AppiumDriverLocalService startAppiumServer() { service = new AppiumServiceBuilder() .withIPAddress("127.0.0.1") .usingPort(PORT) + .withTimeout(Duration.ofSeconds(40)) .build(); service.start(); return service;