From d23b75a1b1c498b81db83dee29a407a3cc6eb9df Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 28 Jun 2024 11:39:11 +0200 Subject: [PATCH] Add E2E tests for Github Actions --- .github/actions/build-ios/action.yml | 12 +++++ .github/actions/install-android/action.yml | 10 ++++ .github/actions/install-ios/action.yml | 24 +++++++++ .github/actions/install-maestro/action.yml | 12 +++++ .github/workflows/e2e-tests.yml | 52 ++++++++++++++++++++ .github/workflows/{ci.yml => unit-tests.yml} | 4 +- 6 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 .github/actions/build-ios/action.yml create mode 100644 .github/actions/install-android/action.yml create mode 100644 .github/actions/install-ios/action.yml create mode 100644 .github/actions/install-maestro/action.yml create mode 100644 .github/workflows/e2e-tests.yml rename .github/workflows/{ci.yml => unit-tests.yml} (96%) diff --git a/.github/actions/build-ios/action.yml b/.github/actions/build-ios/action.yml new file mode 100644 index 0000000..3c9e74f --- /dev/null +++ b/.github/actions/build-ios/action.yml @@ -0,0 +1,12 @@ +name: 'Build iOS App' +description: 'Build the iOS app' +runs: + using: 'composite' + steps: + - name: Build iOS App + run: | + xcodebuild -project ios/WeatherApp.xcodeproj \ + -scheme WeatherApp \ + -configuration Debug \ + -sdk iphonesimulator \ + -derivedDataPath build diff --git a/.github/actions/install-android/action.yml b/.github/actions/install-android/action.yml new file mode 100644 index 0000000..fa954de --- /dev/null +++ b/.github/actions/install-android/action.yml @@ -0,0 +1,10 @@ +name: 'Install Android dependencies' +description: 'Install dependencies for the project' +runs: + using: 'composite' + steps: + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' diff --git a/.github/actions/install-ios/action.yml b/.github/actions/install-ios/action.yml new file mode 100644 index 0000000..5de951b --- /dev/null +++ b/.github/actions/install-ios/action.yml @@ -0,0 +1,24 @@ +name: 'Install iOS dependencies' +description: 'Install dependencies for the project' +runs: + using: 'composite' + steps: + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + bundler-cache: true + + - name: Install Bundler + shell: bash + run: bundle install + working-directory: ios + + - name: Install CocoaPods + shell: bash + run: sudo gem install cocoapods + + - name: Install Pods + shell: bash + run: pod install + working-directory: ios diff --git a/.github/actions/install-maestro/action.yml b/.github/actions/install-maestro/action.yml new file mode 100644 index 0000000..2adb7e8 --- /dev/null +++ b/.github/actions/install-maestro/action.yml @@ -0,0 +1,12 @@ +name: 'Install Maestro dependencies' +description: 'Install dependencies for the project' +runs: + using: 'composite' + steps: + - name: Install dependencies and Maestro + shell: bash + run: | + export MAESTRO_VERSION=1.36.0 + curl -Ls "https://get.maestro.mobile.dev" | bash + brew tap facebook/fb + brew install facebook/fb/idb-companion diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml new file mode 100644 index 0000000..d0ad9a3 --- /dev/null +++ b/.github/workflows/e2e-tests.yml @@ -0,0 +1,52 @@ +name: E2E Tests + +on: + push: + branches: ['main'] + pull_request: + branches: ['main'] + +jobs: + run-e2e-tests: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/install + - uses: ./.github/actions/install-ios + - uses: ./.github/actions/install-android + - uses: ./.github/actions/install-maestro + - uses: ./.github/actions/build-ios + + - name: Start iOS Simulator + run: | + # Find a simulator by name (e.g., iPhone 15) + DEVICE_ID=$(xcrun simctl list devices available --json | jq -r '.devices[] | .[] | select(.name == "iPhone 15") | .udid' | head -n 1) + DEVICE_STATE=$(xcrun simctl list devices available --json | jq -r --arg DEVICE_ID "$DEVICE_ID" '.devices[] | .[] | select(.udid == $DEVICE_ID) | .state') + + if [ -z "$DEVICE_ID" ]; then + echo "No available simulator found for the criteria." + exit 1 + fi + + echo "DEVICE_ID=$DEVICE_ID" >> $GITHUB_ENV + + if [ "$DEVICE_STATE" != "Booted" ]; then + # Boot the simulator if it's not already booted + xcrun simctl boot "$DEVICE_ID" + # Wait a bit for the simulator to boot + sleep 30 + DEVICE_STATE=$(xcrun simctl list devices available --json | jq -r --arg DEVICE_ID "$DEVICE_ID" '.devices[] | .[] | select(.udid == $DEVICE_ID) | .state') + if [ "$DEVICE_STATE" != "Booted" ]; then + echo "Failed to boot the simulator in 30s with DEVICE_ID=$DEVICE_ID." + exit 1 + fi + else + echo "Simulator with DEVICE_ID=$DEVICE_ID is already booted." + fi + + - name: Run Maestro UI tests + run: | + export PATH="$PATH:$HOME/.maestro/bin" + xcrun simctl install $DEVICE_ID build/Build/Products/Debug-iphonesimulator/WeatherApp.app + maestro --device $DEVICE_ID test ./maestro/flow.yml APP_ID=org.reactjs.native.example.WeatherApp diff --git a/.github/workflows/ci.yml b/.github/workflows/unit-tests.yml similarity index 96% rename from .github/workflows/ci.yml rename to .github/workflows/unit-tests.yml index c74116a..c9df6d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/unit-tests.yml @@ -1,7 +1,7 @@ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs -name: CI +name: Unit Tests on: push: @@ -10,7 +10,7 @@ on: branches: ['main'] jobs: - unit-tests: + run-unit-tests: runs-on: ubuntu-latest strategy: