-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathrun-android-tests.sh
More file actions
executable file
·231 lines (183 loc) · 6.55 KB
/
run-android-tests.sh
File metadata and controls
executable file
·231 lines (183 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
set -e # Exit on error
set -x # Print commands
###############################################################################
# Android Emulator Test Runner
#
# This script installs apps on Android emulator, captures debug info,
# and runs Maestro tests.
#
# Usage: ./run-android-tests.sh <working-directory>
###############################################################################
WORKING_DIR="${1:-.}"
DEBUG_DIR="$WORKING_DIR/debug-artifacts"
APP_PACKAGE="com.reown.appkit.expomultichain"
WALLET_PACKAGE="com.walletconnect.web3wallet.rnsample.internal"
###############################################################################
# Setup and Preparation
###############################################################################
echo "Setting up debug directory..."
mkdir -p "$DEBUG_DIR"
echo "Waiting for emulator to be ready..."
adb wait-for-device
echo "Waiting for boot completion..."
adb shell 'while [ "$(getprop sys.boot_completed)" != "1" ]; do sleep 2; done'
echo "Boot completed!"
adb devices
###############################################################################
# Start Logcat Capture
###############################################################################
echo "Starting logcat capture..."
adb logcat -c
adb logcat > "$DEBUG_DIR/full-logcat.txt" &
LOGCAT_PID=$!
# Ensure logcat is killed on script exit
trap "kill $LOGCAT_PID 2>/dev/null || true" EXIT
###############################################################################
# Install Applications
###############################################################################
echo "Installing APKs..."
adb install -r "$WORKING_DIR/app-dev.apk"
adb install -r "$WORKING_DIR/wallet.apk"
echo "Verifying app installation..."
if ! adb shell pm list packages | grep -q "$APP_PACKAGE"; then
echo "ERROR: App not installed correctly"
exit 1
fi
if ! adb shell pm list packages | grep -q "$WALLET_PACKAGE"; then
echo "ERROR: Wallet not installed correctly"
exit 1
fi
echo "Checking APK details:"
adb shell dumpsys package "$APP_PACKAGE" | grep -A 5 "versionName" || true
echo "Clearing app data for clean state..."
adb shell pm clear "$APP_PACKAGE" || true
echo "Waiting for system to settle..."
sleep 5
###############################################################################
# Capture Debug Information
###############################################################################
echo "=== CAPTURING DEBUG INFO ==="
# Network state (critical for WalletConnect)
echo "Capturing network state..."
{
echo "Network state:"
adb shell dumpsys connectivity
adb shell settings get global airplane_mode_on
} > "$DEBUG_DIR/network_state.txt"
# Memory info
echo "Capturing memory info..."
adb shell dumpsys meminfo "$APP_PACKAGE" > "$DEBUG_DIR/meminfo.txt" || true
# Process info
echo "Capturing process info..."
adb shell ps | grep reown > "$DEBUG_DIR/processes.txt" || true
# Manual app launch test
echo "Attempting manual app launch..."
adb shell monkey -p "$APP_PACKAGE" -c android.intent.category.LAUNCHER 1
sleep 5
# Verify app is running
if ! adb shell ps | grep -q "$APP_PACKAGE"; then
echo "WARNING: App may not be running"
fi
# Screenshot before tests
echo "Taking screenshot..."
adb shell screencap /sdcard/app_state_before_maestro.png
adb pull /sdcard/app_state_before_maestro.png "$DEBUG_DIR/" || true
# Current activity
echo "Current activity before Maestro:"
adb shell dumpsys activity activities | grep -E "mResumedActivity|mFocusedActivity" || true
###############################################################################
# Run Maestro Tests
###############################################################################
echo "=== RUNNING MAESTRO TESTS ==="
# Track test results for GitHub Actions output
# Define tests array: filename:display_name
tests=(
"basic-smoke-test:Basic Smoke Test"
"wallet-qr-load:Wallet QR Load"
"switch-network:Switch Network"
"account-activity:Account Activity"
"send:Send"
"swaps:Swaps"
"onramp:Onramp"
)
# Initialize result tracking
test_results=""
failed_tests=""
passed_count=0
failed_count=0
# Run each test and track results
MAX_RETRIES=2
for test_pair in "${tests[@]}"; do
test_file="${test_pair%%:*}"
test_name="${test_pair##*:}"
echo ""
echo "📱 Running $test_name..."
# Record start time
start_time=$(date +%s)
# Retry logic
attempt=0
test_passed=false
while [ $attempt -le $MAX_RETRIES ]; do
if [ $attempt -gt 0 ]; then
echo "⚠️ Retry attempt $attempt for $test_name..."
sleep 3 # Brief pause between retries
fi
if (cd "$WORKING_DIR/.maestro" && maestro test "$test_file.yaml"); then
test_passed=true
break
else
attempt=$((attempt + 1))
fi
done
end_time=$(date +%s)
duration=$((end_time - start_time))
if [ "$test_passed" = true ]; then
echo "✅ $test_name passed (${duration}s)"
if [ $attempt -gt 0 ]; then
test_results="${test_results}✅ $test_name (${duration}s, passed after $attempt retries)\n"
else
test_results="${test_results}✅ $test_name (${duration}s)\n"
fi
passed_count=$((passed_count + 1))
else
echo "❌ $test_name failed after $MAX_RETRIES retries (${duration}s)"
test_results="${test_results}❌ $test_name (${duration}s, failed after $MAX_RETRIES retries)\n"
failed_tests="${failed_tests}• $test_name\n"
failed_count=$((failed_count + 1))
fi
done
# Output results to GitHub Actions
if [ -n "$GITHUB_OUTPUT" ]; then
echo "test_results<<EOF" >> "$GITHUB_OUTPUT"
echo -e "$test_results" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "failed_tests<<EOF" >> "$GITHUB_OUTPUT"
echo -e "$failed_tests" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "passed_count=$passed_count" >> "$GITHUB_OUTPUT"
echo "failed_count=$failed_count" >> "$GITHUB_OUTPUT"
fi
# Print summary
echo ""
echo "=== TEST SUMMARY ==="
echo "Passed: $passed_count"
echo "Failed: $failed_count"
echo ""
echo -e "$test_results"
# Exit with error if any tests failed
if [ $failed_count -gt 0 ]; then
echo "Some tests failed"
exit 1
fi
echo "All tests passed! ✓"
###############################################################################
# Post-Test Diagnostics
###############################################################################
echo "Checking for crashes..."
if adb logcat -d | grep -E "FATAL EXCEPTION|AndroidRuntime|Process:.*com.reown" > "$DEBUG_DIR/crashes.txt"; then
echo "WARNING: Crashes detected, check $DEBUG_DIR/crashes.txt"
else
echo "No crashes found" > "$DEBUG_DIR/crashes.txt"
fi
echo "=== TEST RUN COMPLETE ==="