Skip to content

Commit 0201e65

Browse files
committed
tests: enable automatic tests on Android.
1 parent 7d540b4 commit 0201e65

File tree

8 files changed

+20345
-0
lines changed

8 files changed

+20345
-0
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,55 @@ jobs:
7070
path: /github/home/go/src/github.com/BitBoxSwiss/bitbox-wallet-app/frontends/android/BitBoxApp/app/build/outputs/apk/debug/app-debug.apk
7171
name: BitBoxApp-android-${{github.sha}}.apk
7272
if-no-files-found: error
73+
74+
e2e-android:
75+
name: Android E2E Tests
76+
needs: android
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Checkout repo
80+
uses: actions/checkout@v4
81+
82+
- name: Set up Node.js
83+
uses: actions/setup-node@v4
84+
with:
85+
node-version: '20'
86+
87+
- name: Download APK
88+
uses: actions/download-artifact@v4
89+
with:
90+
name: BitBoxApp-android-${{ github.sha }}.apk
91+
path: frontends/tests/apk
92+
93+
- name: Install dependencies
94+
working-directory: frontends/tests
95+
run: npm ci
96+
97+
- name: Enable KVM group perms
98+
run: |
99+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
100+
sudo udevadm control --reload-rules
101+
sudo udevadm trigger --name-match=kvm
102+
103+
- name: Install Appium & drivers
104+
run: |
105+
npm install -g appium
106+
appium driver install uiautomator2
107+
108+
- name: Start Android emulator and run tests
109+
uses: reactivecircus/android-emulator-runner@v2
110+
env:
111+
PLATFORM: Android
112+
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL: 5
113+
with:
114+
api-level: 34
115+
target: google_apis
116+
arch: x86_64
117+
force-avd-creation: true
118+
emulator-boot-timeout: 600
119+
working-directory: frontends/tests
120+
emulator-options: "-no-window -no-audio -no-boot-anim -no-snapshot-load -no-snapshot-save"
121+
script: ./run.sh
73122
qt-linux:
74123
runs-on: ubuntu-22.04
75124
needs: setup-env

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
SHELL := /bin/bash
1616
WEBROOT := frontends/web
17+
MOBILETESTROOT := frontends/tests
1718

1819
catch:
1920
@echo "Choose a make target."
@@ -57,6 +58,8 @@ webserve:
5758
cd ${WEBROOT} && $(MAKE) serve
5859
webe2etest:
5960
cd ${WEBROOT} && $(MAKE) test-e2e
61+
mobilee2etest:
62+
cd ${MOBILETESTROOT} && ./run.sh
6063
qt-linux: # run inside dockerdev
6164
$(MAKE) buildweb
6265
cd frontends/qt && $(MAKE) linux

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ Playwright is used to perform automatic test on some use cases on the webdev ver
103103
Tests are located under [`frontends/web/tests`](/frontends/web/tests) and can be run with
104104
`make webe2etest`
105105

106+
Appium is used to perform automatic test on Android emulators.
107+
The test runs automatically on PRs and push to master in the Github CI.
108+
106109
#### Run the HTTP API
107110

108111
Run `make servewallet` to compile the code and run `servewallet`. `servewallet` is a devtool which

frontends/tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

frontends/tests/e2e/base.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { remote } from "webdriverio";
2+
import { expect } from "chai";
3+
4+
// --- Test ---
5+
describe("BitBoxApp Base Test", function () {
6+
this.timeout(180000);
7+
8+
let driver;
9+
before(async () => {
10+
11+
const opts = {
12+
path: '/',
13+
port: 4723,
14+
capabilities: {
15+
platformName: 'Android',
16+
'appium:deviceName': 'Android Emulator',
17+
'appium:automationName': 'UiAutomator2',
18+
'appium:app': `./apk/app-debug.apk`,
19+
'appium:noReset': true,
20+
}
21+
};
22+
23+
driver = await remote(opts);
24+
25+
// Switch to WebView if present
26+
const contexts = await driver.getContexts();
27+
const webview = contexts.find((c) => c.startsWith("WEBVIEW_"));
28+
if (webview) await driver.switchContext(webview);
29+
});
30+
31+
after(async () => {
32+
if (driver) await driver.deleteSession();
33+
});
34+
35+
it("App main page loads", async () => {
36+
const body = await driver.$("body");
37+
const bodyText = await body.getText();
38+
expect(bodyText).to.include(
39+
"Please connect your BitBox and tap the side to continue."
40+
);
41+
});
42+
});

0 commit comments

Comments
 (0)