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+ }
0 commit comments