|
1 | 1 | #!/bin/bash |
2 | 2 | # |
3 | | -# SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors |
| 3 | +# SPDX-FileCopyrightText: 2020-2026 Nextcloud GmbH and Nextcloud contributors |
| 4 | +# SPDX-FileCopyrightText: 2026 Philipp Hasper <vcs@hasper.info> |
4 | 5 | # SPDX-FileCopyrightText: 2020-2024 Tobias Kaminsky <tobias@kaminsky.me> |
5 | 6 | # SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only |
6 | 7 | # |
| 8 | +# Run instrumentation screenshot tests (record or compare) for a given test class/method. |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# ./scripts/androidScreenshotTest <record:true|false> <class-pattern> [method] [darkMode: dark|light|all] [color] |
| 12 | +# |
| 13 | +# Arguments: |
| 14 | +# record "true" to record/update reference screenshots (-Precord), "false" to compare. |
| 15 | +# class name the first matching .java or .kt file under app/src/androidTest/java is passed to the instrumentation runner |
| 16 | +# method name optional test method name to run (appends #method to class). If not given, the entire class's tests run |
| 17 | +# darkMode optional: dark | light | all (if "all", the script runs scripts/runAllScreenshotCombinations). |
| 18 | +# color optional value passed as COLOR to the instrumentation runner, for testing different color themes |
| 19 | +# |
| 20 | +# Behavior notes: |
| 21 | +# - Temporarily sets is_beta to true in app/src/main/res/values/setup.xml and restores it afterwards. |
| 22 | +# - Searches for or launches an emulator AVD named "uiComparison" and sets ANDROID_SERIAL for the run. |
| 23 | +# - Requires adb and emulator on PATH and the repo's ./gradlew wrapper. |
| 24 | +# - Caution: If interrupted the setup.xml change may remain; revert with: |
| 25 | +# git checkout -- app/src/main/res/values/setup.xml |
| 26 | +# |
| 27 | +# Examples: |
| 28 | +# ./scripts/androidScreenshotTest false MyScreenshotTest |
| 29 | +# ./scripts/androidScreenshotTest true MyScreenshotTest testCaptureAll all |
| 30 | +# ./scripts/androidScreenshotTest false MyScreenshotTest "" dark red |
| 31 | +# END_DOCUMENTATION |
7 | 32 | set -e |
8 | 33 |
|
9 | 34 | if [ $# -lt 2 ]; then |
10 | | - echo "1: record: true/false |
11 | | -2: class name |
12 | | -3: method name |
13 | | -4: darkMode: dark/light / \"all\" to run all screenshot combinations |
14 | | -5: color" |
15 | | - |
| 35 | + # Print the documentation from the file header, up until END_DOCUMENTATION, excluding specific lines |
| 36 | + sed -n '2,/^#[[:space:]]*END_DOCUMENTATION/ { |
| 37 | + /^#[[:space:]]*SPDX-FileCopyrightText/ d |
| 38 | + /^#[[:space:]]*SPDX-License-Identifier/ d |
| 39 | + /^#[[:space:]]*END_DOCUMENTATION/ d |
| 40 | + s/^#// |
| 41 | + p |
| 42 | + }' "$0" | sed '/^$/d' |
16 | 43 | exit |
17 | 44 | fi |
18 | 45 |
|
@@ -65,6 +92,20 @@ while read line ; do |
65 | 92 | done < <(adb devices | cut -f1) |
66 | 93 |
|
67 | 94 | if [ "$emulatorIsRunning" == false ] ; then |
| 95 | + if [ -z "$(command -v emulator || true)" ]; then |
| 96 | + echo "emulator not found in PATH; typically located in Android/sdk/emulator" >&2 |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | + if [ -z "$(command -v avdmanager || true)" ]; then |
| 100 | + echo "avdmanager not found in PATH; typically located in Android/sdk/cmdline-tools/latest/bin" >&2 |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + # If emulator of expected name doesn't exist, create it |
| 104 | + # TODO - this was copied from updateScreenshots.sh - move it to a common helper script |
| 105 | + if [[ $(emulator -list-avds | grep uiComparison -c) -eq 0 ]]; then |
| 106 | + (sleep 5; echo "no") | avdmanager create avd -n uiComparison -c 100M -k "system-images;android-28;google_apis;x86" --abi "google_apis/x86" |
| 107 | + fi |
| 108 | + |
68 | 109 | "$(command -v emulator)" -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 & |
69 | 110 | sleep 20 |
70 | 111 | fi |
|
0 commit comments