Cannot run an Appium Test on GitHub Actions + Emulator

ello friends,

I am trying to run an Appium Test on GitHub Actions, but the test is failing with the message:

org.openqa.selenium.SessionNotCreatedException at AdvancedApiDemosTest.java:35

If I run all the steps locally it works, so I guess I am missing something. Do you have any tips on what that can be?Thanks! This is the GitHub Action, for reference.




name: Appium Tests

on:
  push:
    branches: [ main ]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: 17

      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '20'

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Prepare Appium
        run: |
          npm install -g appium
          appium driver install uiautomator2
          appium "--allow-insecure=*:session_discovery" > appium.log &

      - name: Run tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 29
          target: google_apis
          arch: x86
          disable-animations: true
          # The pipe character '|' is crucial here to fix the syntax error.
          # It tells the shell to treat the following lines as a single multi-line script.
          script: |
            # Install test app
            cp ./app/ApiDemos-debug.apk ./app.apk
            adb install -r ./app.apk

            curl -s http://127.0.0.1:4723/status | jq .
            adb devices
            # Run Gradle tests
            ./gradlew test --tests "AdvancedApiDemosTest"
      - name: Upload Appium reports
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: test-reports
          path: appium.log

These tests might be failing dues to CI slowness. You may check how uia2 driver CI process is organised though: appium-uiautomator2-driver/.github/workflows/functional-test.yml at master · appium/appium-uiautomator2-driver · GitHub