Skip to content

Commit

Permalink
Add Javascript Appium test
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-serrano-soria committed May 13, 2024
1 parent 57d2fe8 commit 189ec21
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Android App Test

on: [push]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install app dependencies
run: |
npm ci
- name: Install test dependencies
run: |
npm i --save-dev webdriverio
- name: Install Appium driver
run: |
npx appium driver install uiautomator2
- name: Start Appium server
run: |
npx appium &
sleep 30
- name: Enable KVM group perms
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: Build Framework7 app
run: |
npm run build
- name: Install Cordova
run: |
npm install -g cordova
- name: Add Android platform to Cordova
run: |
cordova platform add android
- name: Build Cordova app
run: |
cordova build android
- name: Set up emulator, install apk and run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
script: |
echo "Emulator has started"
adb install platforms/android/app/build/outputs/apk/debug/app-debug.apk
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
node src/tests/test.py
env:
API_KEY: ${{ secrets.API_KEY }}
43 changes: 43 additions & 0 deletions src/tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const {remote} = require('webdriverio');

const capabilities = {
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'emulator-5554',
'appium:appPackage': 'com.example.framework7',
'appium:appActivity': '.MainActivity',
};

const wdOpts = {
hostname: process.env.APPIUM_HOST || 'localhost',
port: parseInt(process.env.APPIUM_PORT, 10) || 4723,
logLevel: 'info',
capabilities,
};

async function runTest() {
const driver = await remote(wdOpts);
try {
const input = await driver.$('//android.widget.EditText');
await input.waitForExist(600000); // wait up to 10 mins
await input.setValue('What is the capital of Japan?');
const link = await driver.$('//android.widget.TextView[@text="Send"]');
await link.waitForExist(600000); // wait up to 10 mins
await link.click();
const textElement = await driver.$('//android.widget.TextView[@text="Tokyo"]');
await textElement.waitForExist(600000); // wait up to 10 mins
const text = await textElement.getText();

if (text === 'Tokyo') {
console.log('Text "Tokyo" found');
} else {
console.log('Text "Tokyo" not found');
}

} finally {
await driver.pause(3000);
await driver.deleteSession();
}
}

runTest().catch(console.error);

0 comments on commit 189ec21

Please sign in to comment.