diff --git a/.github/workflows/appium_setup.yml b/.github/workflows/appium_setup.yml index b400146..b182973 100644 --- a/.github/workflows/appium_setup.yml +++ b/.github/workflows/appium_setup.yml @@ -9,6 +9,10 @@ on: jobs: appium_test: runs-on: ubuntu-latest + strategy: + matrix: + api-level: [ 28 ] + target: [ default ] permissions: contents: write steps: @@ -25,27 +29,6 @@ jobs: java-version: '17' - - name: Set up NodeJS 18 - uses: actions/setup-node@v4 - with: - node-version: '18.19.0' - - # Run Android Emulator - - name: Run Android Emulator - run: | - echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-28;google_apis;x86_64' - echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n test_device -k 'system-images;android-28;google_apis;x86_64' --force - echo $ANDROID_HOME/emulator/emulator -list-avds - echo "Starting emulator" - nohup $ANDROID_HOME/emulator/emulator -avd test_device -no-snapshot > /dev/null 2>&1 & - $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82' - $ANDROID_HOME/platform-tools/adb devices - echo "Emulator started" - # Use HTTPS repos - - - name: Setup Android SDK - uses: android-actions/setup-android@v3 - - name: Install Flutter uses: subosito/flutter-action@v2 with: @@ -57,5 +40,29 @@ jobs: - name: Install flutter dependencies run: flutter pub get - - name: Install and Run Appium Server - uses: moatazeldebsy/appium-server-gitHub-action@V1.0.4 + - name: Set up NodeJS 18 + uses: actions/setup-node@v4 + with: + node-version: '18.19.0' + + - name: Enable KVM + 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: Run Android Emulator + - name: Install the Emulator + run: | + chmod +x ./scripts/RunAppiumServer.sh + ./scripts/RunAppiumServer.sh + shell: bash + + - name: Run Appium Tests + uses: reactivecircus/android-emulator-runner@v2.27.0 + with: + api-level: ${{ matrix.api-level }} + target: ${{ matrix.target }} + arch: x86_64 + profile: pixel 6a + script: ./gradlew connectedCheck \ No newline at end of file diff --git a/scripts/RunAppiumServer.sh b/scripts/RunAppiumServer.sh new file mode 100755 index 0000000..e895cc7 --- /dev/null +++ b/scripts/RunAppiumServer.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# This script sets up Appium for iOS (XCUITest), Android (uiautomator2), and Flutter testing environments. +# It installs the latest version of Appium globally using npm, then installs drivers for XCUITest, +# Espresso, and Flutter. Finally, it starts Appium in the background and logs its output to a file named "appium.log". + +# Exit immediately if a command exits with a non-zero status. +set -ex + +# Install the latest version of Appium globally. +npm install -g appium@next + +# Install the XCUITest driver for iOS testing. +appium driver install xcuitest + +# Install the Espresso driver for Android testing. +appium driver install uiautomator2 + +# Install the Flutter driver for Flutter testing. +appium driver install --source=npm appium-flutter-driver + +# Display the installed version of Appium. +appium -v + +# Start Appium in the background, redirecting both stdout and stderr to /dev/null to suppress output, +# but also log everything to a file named "appium.log". +appium --log appium.log &>/dev/null & diff --git a/scripts/emulator-up.sh b/scripts/emulator-up.sh new file mode 100644 index 0000000..01818e1 --- /dev/null +++ b/scripts/emulator-up.sh @@ -0,0 +1,23 @@ +#https://docs.travis-ci.com/user/languages/android/ +#https://developer.android.com/training/testing/continuous-integration#:~:text=The%20CI%20system%20detects%20a,or%20emulator%20images%20if%20needed. +#!/bin/bash + +set -e #stop immediately if any error happens + +avd_name=$1 + +if [[ -z "$avd_name" ]]; then + avd_name="avd29" +fi + +#check if emulator works well +emulator -version + +# create virtual device, default using Android 9 Pie image (API Level 28) +echo no | avdmanager create avd -n avd28 -k "system-images;android-29;google_apis;x86_64" + +# start the emulator +emulator -avd avd28 -no-audio -no-window -no-accel & + +# show connected virtual device +adb devices diff --git a/scripts/install-android-sdk.sh b/scripts/install-android-sdk.sh new file mode 100644 index 0000000..96c201a --- /dev/null +++ b/scripts/install-android-sdk.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e #stop immediately if any error happens + +# Install Open JDK SDK +sudo apt update +sudo apt install openjdk-8-jdk -y +sudo update-java-alternatives --set java-1.8.0-openjdk-amd64 +sudo apt-get install android-sdk + +java -version + +# Install SDK Manager +# you can find this file at https://developer.android.com/studio/index.html#downloads android studio downloads section (command line tools only) +cd ~ && wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip +ANDROID_HOME=/opt/androidsdk +mkdir -p $ANDROID_HOME +sudo apt install unzip -y && unzip sdk-tools-linux-4333796.zip -d $ANDROID_HOME + +echo "export ANDROID_HOME=$ANDROID_HOME" >> ~/.bashrc +echo 'export SDK=$ANDROID_HOME' >> ~/.bashrc +echo 'export PATH=$SDK/emulator:$SDK/tools:$SDK/tools/bin:$SDK/platform-tools:$PATH' >> ~/.bashrc +source ~/.bashrc + +# Install Android Image version 29 +yes | sudo sdkmanager "platform-tools" "platforms;android-29" "emulator" +yes | sudo sdkmanager "system-images;android-29;google_apis;x86_64" +emulator -version + +echo "INSTALL ANDROID SDK DONE!"