Skip to content

Commit 9ab083b

Browse files
fix: use android-emulator-runner
1 parent 43c8eb0 commit 9ab083b

2 files changed

Lines changed: 129 additions & 13 deletions

File tree

.github/workflows/e2e.yml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ jobs:
120120
key: ${{ steps.derived-data-cache.outputs.cache-primary-key }}
121121

122122
- name: Upload test artifacts
123-
if: failure()
124123
uses: actions/upload-artifact@v4
125124
with:
126125
name: e2e-ios-artifacts
127126
path: |
128-
.maestro/screenshots/ios/*_diff.png
127+
.maestro/enrichedInput/screenshots/ios/*_diff.png
128+
.maestro/enrichedText/screenshots/ios/*_diff.png
129129
130130
e2e-android:
131131
needs: [changes]
@@ -151,14 +151,6 @@ jobs:
151151
distribution: 'zulu'
152152
java-version: '17'
153153

154-
- name: Finalize Android SDK
155-
run: |
156-
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
157-
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "emulator" "platform-tools"
158-
echo "$ANDROID_HOME/cmdline-tools/latest/bin" >> $GITHUB_PATH
159-
echo "$ANDROID_HOME/platform-tools" >> $GITHUB_PATH
160-
echo "$ANDROID_HOME/emulator" >> $GITHUB_PATH
161-
162154
- name: Install Maestro CLI
163155
run: |
164156
curl -Ls "https://get.maestro.mobile.dev" | bash
@@ -174,18 +166,52 @@ jobs:
174166
restore-keys: |
175167
${{ runner.os }}-gradle-
176168
169+
- name: AVD cache
170+
uses: actions/cache@v4
171+
id: avd-cache
172+
with:
173+
path: |
174+
~/.android/avd/*
175+
~/.android/adb*
176+
key: avd-api-36-x86_64
177+
178+
- name: Create AVD and generate snapshot for caching
179+
if: steps.avd-cache.outputs.cache-hit != 'true'
180+
uses: reactivecircus/android-emulator-runner@v2
181+
with:
182+
api-level: 36
183+
target: google_apis_playstore
184+
arch: x86_64
185+
profile: pixel_7
186+
force-avd-creation: false
187+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim
188+
disable-animations: false
189+
enable-hw-keyboard: true
190+
script: echo "Generated AVD snapshot for caching."
191+
177192
- name: Start Metro
178193
run: yarn example start &
179194

180195
- name: Run E2E tests
181-
run: yarn test:e2e:android
196+
uses: reactivecircus/android-emulator-runner@v2
197+
with:
198+
api-level: 36
199+
target: google_apis_playstore
200+
arch: x86_64
201+
profile: pixel_7
202+
force-avd-creation: false
203+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim
204+
disable-animations: true
205+
disable-spellchecker: true
206+
enable-hw-keyboard: true
207+
script: EMULATOR_SERIAL=emulator-5554 .maestro/scripts/run-tests-ci-android.sh
182208
env:
183209
JAVA_OPTS: '-XX:MaxHeapSize=6g'
184210

185211
- name: Upload test artifacts
186-
if: failure()
187212
uses: actions/upload-artifact@v4
188213
with:
189214
name: e2e-android-artifacts
190215
path: |
191-
.maestro/screenshots/android/*_diff.png
216+
.maestro/enrichedInput/screenshots/android/*_diff.png
217+
.maestro/enrichedText/screenshots/android/*_diff.png
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
# run-tests-ci-android.sh - CI-only script for running Android E2E tests.
3+
#
4+
# Designed to run inside reactivecircus/android-emulator-runner's `script` context
5+
# where the emulator is already booted. Builds the app, installs it, and runs
6+
# maestro tests.
7+
#
8+
# The emulator serial is passed via EMULATOR_SERIAL (defaults to emulator-5554).
9+
10+
set -euo pipefail
11+
12+
MIN_MAESTRO_VERSION="2.3.0"
13+
14+
if ! command -v maestro >/dev/null 2>&1; then
15+
echo "Error: maestro CLI not found." >&2
16+
exit 1
17+
fi
18+
19+
MAESTRO_VERSION=$(maestro --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
20+
if [ "$(printf '%s\n' "$MIN_MAESTRO_VERSION" "$MAESTRO_VERSION" | sort -V | head -n1)" != "$MIN_MAESTRO_VERSION" ]; then
21+
echo "Error: maestro $MAESTRO_VERSION is too old, minimum required is $MIN_MAESTRO_VERSION" >&2
22+
exit 1
23+
fi
24+
25+
SERIAL="${EMULATOR_SERIAL:-emulator-5554}"
26+
27+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
28+
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
29+
MAESTRO_ROOT="$REPO_ROOT/.maestro"
30+
SCREENSHOT_ROOT="$MAESTRO_ROOT"
31+
32+
echo "=== Waiting for emulator to be ready ==="
33+
adb -s "$SERIAL" wait-for-device
34+
until adb -s "$SERIAL" shell getprop sys.boot_completed 2>/dev/null | grep -q "^1$"; do
35+
sleep 2
36+
done
37+
38+
adb -s "$SERIAL" shell pm disable-user --user 0 com.google.android.inputmethod.latin 2>/dev/null || true
39+
adb -s "$SERIAL" shell settings put secure spell_checker_enabled 0
40+
41+
echo "=== Building and installing app ==="
42+
yarn example android --device "$SERIAL"
43+
44+
set_font_scale() {
45+
case "$1" in
46+
default) adb -s "$SERIAL" shell settings put system font_scale 1.0 ;;
47+
large) adb -s "$SERIAL" shell settings put system font_scale 1.5 ;;
48+
esac
49+
}
50+
51+
trap 'set_font_scale default' EXIT
52+
set_font_scale default
53+
54+
FLOWS=".maestro/enrichedInput/flows .maestro/enrichedText/flows"
55+
ASSETS_DIR="$MAESTRO_ROOT/assets"
56+
[ -d "$ASSETS_DIR" ] && FLOWS="$ASSETS_DIR $FLOWS"
57+
58+
EXTRA="--env SCREENSHOT_ROOT=$SCREENSHOT_ROOT --exclude-tags ios-only"
59+
60+
run_maestro() {
61+
local tmp rc
62+
tmp=$(mktemp)
63+
local cmd
64+
cmd=$(printf '%q ' maestro test "$@")
65+
script -qec "$cmd" /dev/null 2>&1 | tee "$tmp"
66+
rc=${PIPESTATUS[0]}
67+
if [ "$rc" -ne 0 ] && grep -q "did not match any Flows" "$tmp"; then
68+
echo "warn: no flows matched the tag filter — treating as success" >&2
69+
rc=0
70+
fi
71+
rm -f "$tmp"
72+
return "$rc"
73+
}
74+
75+
set +e
76+
77+
echo "=== Running maestro tests ==="
78+
# shellcheck disable=SC2086
79+
run_maestro --device "$SERIAL" --exclude-tags accessibility $EXTRA $FLOWS
80+
EXIT_REGULAR=$?
81+
82+
echo "=== Running maestro accessibility tests ==="
83+
set_font_scale large
84+
# shellcheck disable=SC2086
85+
run_maestro --device "$SERIAL" --include-tags accessibility $EXTRA $FLOWS
86+
EXIT_A11Y=$?
87+
88+
set -e
89+
90+
exit $(( EXIT_REGULAR != 0 || EXIT_A11Y != 0 ))

0 commit comments

Comments
 (0)