Skip to content

Commit 04697c9

Browse files
committed
Update config
1 parent 97327f6 commit 04697c9

File tree

2 files changed

+112
-26
lines changed

2 files changed

+112
-26
lines changed

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: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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"
33-
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-
}
50-
51-
# Run the single test
52-
run_single_test
53-
54-
echo "🎉 All tests completed successfully!"
55-
exit 0
30+
# Define the test file
31+
TEST_FILE="maestro/tests/AppStartup.yaml"
32+
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
38+
39+
# Run the test with retries
40+
run_test_with_retries "$TEST_FILE"
41+
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)