summaryrefslogtreecommitdiffhomepage
path: root/android/scripts
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2023-01-26 10:01:35 +0100
committerAlbin <albin@mullvad.net>2023-01-26 10:01:35 +0100
commit4d04748a2e9dfe4d07fe5c24999f8eceabc3cb0d (patch)
treeb25a0f9f9f43772953e6ef2228ac7cc0ad5f0265 /android/scripts
parent01f0e5f473f82c2434ec3cfb7ba509f8494efbcc (diff)
parent4d67f4393492a3f1df46302b70edf4a6ee0f40bf (diff)
downloadmullvadvpn-4d04748a2e9dfe4d07fe5c24999f8eceabc3cb0d.tar.xz
mullvadvpn-4d04748a2e9dfe4d07fe5c24999f8eceabc3cb0d.zip
Merge branch 'run-mockapi-tests-in-gh-actions'
Diffstat (limited to 'android/scripts')
-rwxr-xr-xandroid/scripts/run-instrumented-tests.sh64
1 files changed, 47 insertions, 17 deletions
diff --git a/android/scripts/run-instrumented-tests.sh b/android/scripts/run-instrumented-tests.sh
index 461a9e9d59..5e855ca242 100755
--- a/android/scripts/run-instrumented-tests.sh
+++ b/android/scripts/run-instrumented-tests.sh
@@ -5,8 +5,14 @@ set -eu
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
+AUTO_FETCH_TEST_HELPER_APKS=${AUTO_FETCH_TEST_HELPER_APKS:-"false"}
+
APK_BASE_DIR=${APK_BASE_DIR:-"$SCRIPT_DIR/.."}
LOG_FAILURE_MESSAGE="FAILURES!!!"
+DEFAULT_ORCHESTRATOR_APK_PATH=/tmp/orchestrator.apk
+ORCHESTRATOR_URL=https://dl.google.com/android/maven2/androidx/test/orchestrator/1.4.2/orchestrator-1.4.2.apk
+DEFAULT_TEST_SERVICES_APK_PATH=/tmp/test-services.apk
+TEST_SERVICES_URL=https://dl.google.com/android/maven2/androidx/test/services/test-services/1.4.2/test-services-1.4.2.apk
while [[ "$#" -gt 0 ]]; do
case $1 in
@@ -52,25 +58,41 @@ if [[ -z ${TEST_TYPE-} ]]; then
exit 1
fi
-if [[ "${USE_ORCHESTRATOR-}" == "true" ]]; then
- if [[ -z ${ORCHESTRATOR_APK_PATH-} ]]; then
- echo "The variable ORCHESTRATOR_APK_PATH is not set."
- exit 1
- fi
- if [[ -z ${TEST_SERVICES_APK_PATH-} ]]; then
- echo "The variable TEST_SERVICES_APK_PATH is not set."
- exit 1
- fi
-fi
+LOCAL_TMP_REPORT_PATH="/tmp/mullvad-$TEST_TYPE-instrumentation-report"
+INSTRUMENTATION_LOG_FILE_PATH="$LOCAL_TMP_REPORT_PATH/instrumentation-log.txt"
+LOGCAT_FILE_PATH="$LOCAL_TMP_REPORT_PATH/logcat.txt"
+LOCAL_SCREENSHOT_PATH="$LOCAL_TMP_REPORT_PATH/screenshots"
+DEVICE_SCREENSHOT_PATH="/sdcard/Pictures/mullvad-$TEST_TYPE"
-LOG_FILE_NAME="mullvad-$TEST_TYPE.txt"
-LOG_FILE_PATH="/tmp/$LOG_FILE_NAME"
+echo "Preparing to run tests of type: $TEST_TYPE"
+echo ""
-echo "Starting instrumented tests of type: $TEST_TYPE"
+echo "### Ensure clean report structure ###"
+rm -rf "$LOCAL_TMP_REPORT_PATH" || echo "No report path"
+adb logcat --clear
+adb shell rm -rf "$DEVICE_SCREENSHOT_PATH"
+mkdir "$LOCAL_TMP_REPORT_PATH"
echo ""
-echo "### Clean up previous logs ###"
-rm "$LOG_FILE_PATH"
+if [[ "${USE_ORCHESTRATOR-}" == "true" ]]; then
+ if [[ "${AUTO_FETCH_TEST_HELPER_APKS-}" == "true" ]]; then
+ echo "### Fetching orchestrator and test services apks ###"
+ ORCHESTRATOR_APK_PATH=$DEFAULT_ORCHESTRATOR_APK_PATH
+ TEST_SERVICES_APK_PATH=$DEFAULT_TEST_SERVICES_APK_PATH
+ curl -sL "$ORCHESTRATOR_URL" -o "$ORCHESTRATOR_APK_PATH"
+ curl -sL "$TEST_SERVICES_URL" -o "$TEST_SERVICES_APK_PATH"
+ echo ""
+ else
+ if [[ -z ${ORCHESTRATOR_APK_PATH-} ]]; then
+ echo "The variable ORCHESTRATOR_APK_PATH is not set."
+ exit 1
+ fi
+ if [[ -z ${TEST_SERVICES_APK_PATH-} ]]; then
+ echo "The variable TEST_SERVICES_APK_PATH is not set."
+ exit 1
+ fi
+ fi
+fi
echo "### Ensure that packages are not previously installed ###"
adb uninstall net.mullvad.mullvadvpn || echo "App package not installed"
@@ -79,11 +101,16 @@ adb uninstall androidx.test.services || echo "Test services package not installe
adb uninstall androidx.test.orchestrator || echo "Test orchestrator package not installed"
echo ""
+echo "Starting instrumented tests of type: $TEST_TYPE"
+echo ""
+
echo "### Install packages ###"
adb install -t "$APK_BASE_DIR/app/build/outputs/apk/debug/app-debug.apk"
adb install "$TEST_APK"
if [[ "$USE_ORCHESTRATOR" == "true" ]]; then
+ echo "Using ORCHESTRATOR_APK_PATH: $ORCHESTRATOR_APK_PATH"
adb install "$ORCHESTRATOR_APK_PATH"
+ echo "Using TEST_SERVICES_APK_PATH: $TEST_SERVICES_APK_PATH"
adb install "$TEST_SERVICES_APK_PATH"
fi
echo ""
@@ -102,7 +129,7 @@ else
am instrument -w \
$TEST_PACKAGE/androidx.test.runner.AndroidJUnitRunner"
fi
-adb shell "$INSTRUMENTATION_COMMAND" | tee "$LOG_FILE_PATH"
+adb shell "$INSTRUMENTATION_COMMAND" | tee "$INSTRUMENTATION_LOG_FILE_PATH"
echo ""
echo "### Ensure that packages are uninstalled ###"
@@ -113,8 +140,11 @@ adb uninstall androidx.test.orchestrator || echo "Test orchestrator package not
echo ""
echo "### Checking logs for failures ###"
-if grep -q "$LOG_FAILURE_MESSAGE" "$LOG_FILE_PATH"; then
+if grep -q "$LOG_FAILURE_MESSAGE" "$INSTRUMENTATION_LOG_FILE_PATH"; then
echo "One or more tests failed, see logs for more details."
+ echo "Collecting report..."
+ adb pull "$DEVICE_SCREENSHOT_PATH" "$LOCAL_SCREENSHOT_PATH" || echo "No screenshots"
+ adb logcat -d > "$LOGCAT_FILE_PATH"
exit 1
else
echo "No failures!"