Skip to content

Commit 1c06f3b

Browse files
committed
Update config
1 parent 97327f6 commit 1c06f3b

File tree

3 files changed

+174
-25
lines changed

3 files changed

+174
-25
lines changed

.github/workflows/MiNe2e.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,66 @@ jobs:
191191
name: android-screenshots
192192
path: ${{ github.workspace }}/maestro/tests/images/actual/android/**/*.png
193193
if-no-files-found: ignore
194+
195+
compare-screenshots:
196+
needs: [android-test]
197+
runs-on: ubuntu-latest
198+
if: always()
199+
env:
200+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201+
steps:
202+
- name: "Check out code"
203+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
204+
205+
206+
- name: "Download all Android screenshots"
207+
run: |
208+
mkdir -p images/actual/android/
209+
echo "Downloading all Android screenshots..."
210+
gh run download ${{ github.run_id }} --name android-screenshots --dir images/actual/android/ || echo "⚠️ Failed to download Android screenshots."
211+
ls -l images/actual/android/
212+
213+
- name: "Download all iOS screenshots"
214+
run: |
215+
mkdir -p images/actual/ios/
216+
echo "Downloading all iOS screenshots..."
217+
gh run download ${{ github.run_id }} --name ios-screenshots --dir images/actual/ios/ || echo "⚠️ Failed to download iOS screenshots."
218+
ls -l images/actual/ios/
219+
220+
- name: "Set up node"
221+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
222+
with:
223+
node-version-file: .nvmrc
224+
cache: npm
225+
226+
- name: "Install pixelmatch"
227+
run: npm install pixelmatch
228+
229+
- name: "Compare Android screenshots"
230+
continue-on-error: true
231+
run: node ${{ github.workspace }}/maestro/helpers/compare_screenshots.js android
232+
233+
- name: "Compare iOS screenshots"
234+
continue-on-error: true
235+
run: node ${{ github.workspace }}/maestro/helpers/compare_screenshots.js ios
236+
237+
- name: "Archive diff results"
238+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #v4
239+
with:
240+
name: screenshot-diffs
241+
path: images/diffs
242+
if-no-files-found: ignore
243+
244+
- name: "Archive comparison results"
245+
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #v4
246+
with:
247+
name: comparison-results
248+
path: compare_output.txt
249+
if-no-files-found: ignore
250+
251+
- name: "Fail if comparisons failed"
252+
run: |
253+
if [ "$ANDROID_COMPARISON_FAILED" == "true" ] || [ "$IOS_COMPARISON_FAILED" == "true" ]; then
254+
echo "One or more comparisons failed."
255+
exit 1
256+
fi

maestro/helpers/helpers.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
MAX_RETRIES=3
4+
RETRY_DELAY=10
5+
6+
# Function to restart the iOS simulator
7+
restart_simulator() {
8+
echo "🔄 Restarting iOS Simulator..."
9+
xcrun simctl shutdown "$IOS_DEVICE"
10+
sleep 10
11+
bash ./maestro/helpers/prepare_ios.sh
12+
}
13+
14+
# Function to set the status bar on the Android emulator
15+
set_status_bar() {
16+
echo "Setting status bar on Android Emulator..."
17+
adb root
18+
adb shell "date -u 11010000" # Set time to 11:01 - due to some bug it always sets to 12:00
19+
adb shell svc wifi enable # Enable Wi-Fi
20+
adb shell svc data enable # Enable mobile data
21+
adb shell dumpsys battery set level 100 # Set battery level to 100%
22+
adb shell dumpsys battery set status 2 # Set battery status to charging
23+
adb reverse tcp:8080 tcp:8080 # Reverse port 8080
24+
25+
# Verify the status bar settings
26+
retries=0
27+
max_retries=5
28+
while [ $retries -lt $max_retries ]; do
29+
current_time=$(adb shell "date +%H:%M")
30+
if [ "$current_time" == "00:00" ]; then
31+
echo "Status bar set successfully."
32+
break
33+
else
34+
echo "Retrying status bar settings..."
35+
adb shell "date -u 11010000"
36+
sleep 2
37+
retries=$((retries + 1))
38+
fi
39+
done
40+
41+
if [ $retries -eq $max_retries ]; then
42+
echo "Failed to set status bar after $max_retries attempts."
43+
fi
44+
}
45+
46+
# Function to ensure the emulator is ready
47+
ensure_emulator_ready() {
48+
boot_completed=false
49+
while [ "$boot_completed" == "false" ]; do
50+
boot_completed=$(adb -s emulator-5554 shell getprop sys.boot_completed 2>/dev/null)
51+
if [ "$boot_completed" == "1" ]; then
52+
echo "Emulator is ready."
53+
break
54+
else
55+
echo "Waiting for emulator to be ready..."
56+
sleep 5
57+
fi
58+
done
59+
}
60+
61+
# Function to run tests
62+
run_test_with_retries() {
63+
local test_file="$1"
64+
local attempt=0
65+
66+
while [ $attempt -lt $MAX_RETRIES ]; do
67+
echo "🚀 Running test: $test_file (Attempt $((attempt + 1))/$MAX_RETRIES)"
68+
69+
# Ensure emulator is ready before each attempt
70+
ensure_emulator_ready
71+
72+
# Set the status bar for Android
73+
if [ "$PLATFORM" == "android" ]; then
74+
set_status_bar
75+
fi
76+
77+
if $HOME/.local/bin/maestro/bin/maestro test --env APP_ID=$APP_ID --env PLATFORM=$PLATFORM --env MAESTRO_DRIVER_STARTUP_TIMEOUT=300000 "$test_file"; then
78+
echo "✅ Test passed: $test_file"
79+
return 0
80+
else
81+
echo "❌ Test failed: $test_file (Attempt $((attempt + 1))/$MAX_RETRIES)"
82+
attempt=$((attempt + 1))
83+
if [ $attempt -lt $MAX_RETRIES ]; then
84+
echo "Retrying in $RETRY_DELAY seconds..."
85+
sleep $RETRY_DELAY
86+
fi
87+
fi
88+
done
89+
90+
echo "❌ Test failed after $MAX_RETRIES attempts: $test_file"
91+
return 1
92+
}

maestro/run_maestro_tests.sh

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ SCRIPT_DIR=$(dirname "$0")
88
# Source the helpers.sh script from the script's directory
99
source "$SCRIPT_DIR/helpers/helpers.sh" || { echo "Failed to source helpers.sh"; exit 1; }
1010

11-
# Check if run_tests function is available
12-
command -v run_tests >/dev/null 2>&1 || { echo "run_tests function not found"; exit 1; }
11+
# Check if run_test_with_retries function is available
12+
command -v run_test_with_retries >/dev/null 2>&1 || { echo "run_test_with_retries function not found"; exit 1; }
1313

1414
if [ "$1" == "android" ]; then
1515
APP_ID="com.mendix.developerapp.mx10"
@@ -27,29 +27,23 @@ passed_tests=()
2727
failed_tests=()
2828
final_failed_tests=()
2929

30-
# Run the single test file
31-
run_single_test() {
32-
local test_file="maestro/tests/AppStartup.yaml"
30+
# Define the test file
31+
TEST_FILE="maestro/tests/AppStartup.yaml"
3332

34-
if [ ! -f "$test_file" ]; then
35-
echo "❌ Test file not found: $test_file"
36-
exit 1
37-
fi
38-
39-
echo "🚀 Running test: $test_file"
40-
run_tests "$test_file"
41-
42-
# Check results
43-
if [ ${#passed_tests[@]} -gt 0 ]; then
44-
echo "✅ Test passed: $test_file"
45-
else
46-
echo "❌ Test failed: $test_file"
47-
exit 1
48-
fi
49-
}
33+
# Check if the test file exists
34+
if [ ! -f "$TEST_FILE" ]; then
35+
echo "❌ Test file not found: $TEST_FILE"
36+
exit 1
37+
fi
5038

51-
# Run the single test
52-
run_single_test
39+
# Run the test with retries
40+
run_test_with_retries "$TEST_FILE"
5341

54-
echo "🎉 All tests completed successfully!"
55-
exit 0
42+
# Check the result
43+
if [ $? -eq 0 ]; then
44+
echo "🎉 Test completed successfully!"
45+
exit 0
46+
else
47+
echo "❌ Test failed after retries."
48+
exit 1
49+
fi

0 commit comments

Comments
 (0)