|
| 1 | +#!/bin/bash |
| 2 | +set -euxo pipefail |
| 3 | + |
| 4 | +# Find the built APK file |
| 5 | +APK_FILE=$(find dist -name "*.apk" -print -quit) |
| 6 | + |
| 7 | +if [ -z "$APK_FILE" ]; then |
| 8 | + echo "Error: No APK file found in dist/" |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +echo "Installing $APK_FILE..." |
| 13 | +adb install "$APK_FILE" |
| 14 | + |
| 15 | +# Extract package and activity names |
| 16 | +AAPT2_PATH=$(find ${ANDROID_HOME}/build-tools/ -name aapt2 | sort -r | head -n 1) |
| 17 | +APP_PACKAGE=$(${AAPT2_PATH} dump badging "${APK_FILE}" | awk -F"'" '/package: name=/{print $2}') |
| 18 | +APP_ACTIVITY=$(${AAPT2_PATH} dump badging "${APK_FILE}" | awk -F"'" '/launchable-activity/ {print $2}') |
| 19 | + |
| 20 | +echo "Launching $APP_PACKAGE/$APP_ACTIVITY..." |
| 21 | +adb shell am start -n "$APP_PACKAGE/$APP_ACTIVITY" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER |
| 22 | + |
| 23 | +# Poll for test completion with timeout |
| 24 | +MAX_WAIT=300 |
| 25 | +POLL_INTERVAL=5 |
| 26 | +elapsed=0 |
| 27 | + |
| 28 | +echo "Waiting for tests to complete (max ${MAX_WAIT}s)..." |
| 29 | + |
| 30 | +while [ $elapsed -lt $MAX_WAIT ]; do |
| 31 | + # Dump current logs |
| 32 | + adb logcat -d -s python:I *:S > app_logs.txt |
| 33 | + |
| 34 | + # Check if all success patterns are present |
| 35 | + if grep --extended-regexp --quiet "I python[ ]+: Initialized python" app_logs.txt && \ |
| 36 | + grep --extended-regexp --quiet "I python[ ]+: Ran 14 tests in" app_logs.txt && \ |
| 37 | + grep --extended-regexp --quiet "I python[ ]+: OK" app_logs.txt; then |
| 38 | + echo "✅ SUCCESS: App launched and all unit tests passed in ${elapsed}s." |
| 39 | + exit 0 |
| 40 | + fi |
| 41 | + |
| 42 | + # Check for early failure indicators |
| 43 | + if grep --extended-regexp --quiet "I python[ ]+: FAILED" app_logs.txt; then |
| 44 | + echo "❌ FAILURE: Tests failed after ${elapsed}s." |
| 45 | + echo "--- Full Logs ---" |
| 46 | + cat app_logs.txt |
| 47 | + echo "-----------------" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + |
| 51 | + sleep $POLL_INTERVAL |
| 52 | + elapsed=$((elapsed + POLL_INTERVAL)) |
| 53 | + echo "Still waiting... (${elapsed}s elapsed)" |
| 54 | +done |
| 55 | + |
| 56 | +echo "❌ TIMEOUT: Tests did not complete within ${MAX_WAIT}s." |
| 57 | +echo "--- Full Logs ---" |
| 58 | +cat app_logs.txt |
| 59 | +echo "-----------------" |
| 60 | +exit 1 |
0 commit comments