Skip to content

Commit 269321b

Browse files
committed
[test] upload screenshots as artifacts
1 parent f72b684 commit 269321b

File tree

3 files changed

+58
-21
lines changed

3 files changed

+58
-21
lines changed

.github/workflows/ci.yml

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ jobs:
2424
uses: actions/setup-node@v3
2525
with:
2626
node-version: '22'
27+
cache: 'npm'
28+
cache-dependency-path: example/package-lock.json
29+
30+
- name: Cache CocoaPods
31+
uses: actions/cache@v3
32+
with:
33+
path: |
34+
example/ios/Pods
35+
key: ${{ runner.os }}-pods-${{ hashFiles('example/ios/Podfile.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-pods-
2738
2839
- name: Install dependencies
2940
run: |
@@ -32,19 +43,19 @@ jobs:
3243
3344
- name: Install Maestro CLI
3445
run: |
35-
export MAESTRO_VERSION=1.39.13; curl -Ls "https://get.maestro.mobile.dev" | bash
46+
curl -Ls "https://get.maestro.mobile.dev" | bash
3647
brew tap facebook/fb
3748
brew install facebook/fb/idb-companion
3849
3950
- name: Add Maestro to path
4051
run: echo "${HOME}/.maestro/bin" >> $GITHUB_PATH
4152

42-
- name: Bundle iOS
43-
run: npm run build:ios
53+
- name: Start packager
54+
run: npm start &
4455

4556
- name: Build iOS
4657
run: |
47-
npm run ios:release
58+
npm run ios
4859
4960
- name: Setup iOS simulator
5061
run: |
@@ -53,11 +64,40 @@ jobs:
5364
UDID=$(xcrun simctl list devices available | grep "iPhone" | head -1 | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})")
5465
xcrun simctl boot "${UDID}"
5566
fi
56-
open -a Simulator --args -CurrentDeviceUDID "${UDID}"
67+
open -a Simulator
5768
xcrun simctl launch "${UDID}" com.jscexample
5869
5970
- name: Run iOS tests
60-
run: export MAESTRO_DRIVER_STARTUP_TIMEOUT=190000; npm run test:e2e
71+
run: |
72+
# Set timeouts
73+
export MAESTRO_DRIVER_STARTUP_TIMEOUT=1500000
74+
export MAESTRO_WAIT_TIMEOUT=10000
75+
76+
# Get the UDID of the booted simulator
77+
UDID=$(xcrun simctl list devices | grep "iPhone" | grep "Booted" | head -1 | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})")
78+
if [ -z "$UDID" ]; then
79+
echo "No booted iPhone simulator found"
80+
exit 1
81+
fi
82+
83+
echo "Using simulator with UDID: ${UDID}"
84+
85+
# Find test files
86+
MAESTRO_DIR="./maestro-tests"
87+
88+
# Run each test with a timeout
89+
for TEST_FILE in ${MAESTRO_DIR}/*.yaml; do
90+
echo "Running test: ${TEST_FILE}"
91+
COMMAND="$HOME/.maestro/bin/maestro --udid=\"${UDID}\" test \"${TEST_FILE}\" --format junit"
92+
echo "Executing: ${COMMAND}"
93+
94+
bash -c "${COMMAND}"
95+
96+
EXIT_CODE=$?
97+
if [ $EXIT_CODE -ne 0 ]; then
98+
echo "Test failed: ${TEST_FILE} with exit code ${EXIT_CODE}"
99+
fi
100+
done
61101
62102
android-build:
63103
name: Android Build
@@ -86,12 +126,12 @@ jobs:
86126
- name: Install dependencies
87127
run: npm install --frozen-lockfile
88128

89-
- name: Bundle Android
90-
run: npm run build:android
129+
- name: Start packager
130+
run: npm start &
91131

92132
- name: Install Maestro CLI
93133
run: |
94-
export MAESTRO_VERSION=1.39.13; curl -Ls "https://get.maestro.mobile.dev" | bash
134+
curl -Ls "https://get.maestro.mobile.dev" | bash
95135
96136
- name: Add Maestro to path
97137
run: echo "${HOME}/.maestro/bin" >> $GITHUB_PATH
@@ -112,5 +152,5 @@ jobs:
112152
disable-animations: false
113153
working-directory: example
114154
script: |
115-
npm run android:release
155+
npm run android
116156
npm run test:e2e

example/maestro-tests/base.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
appId: com.jscexample
22
---
3-
- launchApp
4-
- waitForAnimationToEnd:
5-
timeout: 5000
3+
- launchApp:
4+
appId: com.jscexample
5+
- takeScreenshot: MainScreen
66
- assertVisible:
77
text: "Welcome to React Native"
8-
optional: true # Make this assertion optional
98

109
# Console Log Test
1110
- tapOn: "Console Log Test"

example/package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {
6-
"android": "react-native run-android",
7-
"android:release": "react-native run-android --mode Release --no-packager",
8-
"ios:release": "npx react-native run-ios --mode Release --no-packager",
9-
"ios": "react-native run-ios",
6+
"android": "react-native run-android --mode release",
7+
"ios": "react-native run-ios --mode Release",
108
"lint": "eslint .",
119
"start": "react-native start",
1210
"test": "jest",
1311
"mkdist": "node -e \"require('node:fs').mkdirSync('dist', { recursive: true, mode: 0o755 })\"",
14-
"build:android": "npm run mkdist && react-native bundle --entry-file index.js --platform android --dev false --bundle-output dist/main.android.jsbundle --assets-dest dist/res",
15-
"build:ios": "npm run mkdist && react-native bundle --entry-file index.js --platform ios --dev false --bundle-output dist/main.ios.jsbundle --assets-dest dist",
16-
"test:e2e": "maestro test maestro-tests/base.yaml"
12+
"build:android": "npm run mkdist && react-native bundle --entry-file index.js --platform android --bundle-output dist/main.android.jsbundle --assets-dest dist/res --dev false",
13+
"build:ios": "npm run mkdist && react-native bundle --entry-file index.js --platform ios --bundle-output dist/main.ios.jsbundle --assets-dest dist --dev false",
14+
"test:e2e": "maestro test maestro-tests"
1715
},
1816
"dependencies": {
1917
"react": "19.0.0",

0 commit comments

Comments
 (0)