SPB Git

Repository Public

ui-tests.sh 5.0 KB 60 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/ui-tests.sh4# Description: Runs the XCUITest journeys of "SP Vault Dev" against the real local server and writes the screenshots5#              into docs/screenshots. Prepares what the scenarios share: invitations, the CSV to import, a scratch6#              directory (default /tmp/spvault-ui) for passkey files, recovery key and pairing code.7#8# Usage: Scripts/ui-tests.sh mac      journeys 01–03 + 05 on macOS (takes the keyboard and the mouse while it runs)9#        Scripts/ui-tests.sh iphone   journeys 01–03 on the simulator "SPVault iPhone"10#        Scripts/ui-tests.sh ipad     journey 04 (split layout) on "SPVault iPad"11#        Scripts/ui-tests.sh pair     cross-device: the iPhone simulator joins the macOS account (needs `mac` run before)12#        Scripts/ui-tests.sh all      mac, iphone, ipad, pair13set -uo pipefail14export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"15cd "$(dirname "$0")/.."16DD="${SPV_DD:-$HOME/Library/Developer/SPVault/DerivedData}"; DIR="${SPV_UI_DIR:-/tmp/spvault-ui}"; SHOTS="$PWD/docs/screenshots"17mkdir -p build/logs "$DIR" "$SHOTS"18sim() { xcrun simctl list devices | grep -F "$1 (" | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/'; }19prepare() {20  Scripts/dev-server.sh up || exit 121  : > "$DIR/invites.txt"22  for i in 1 2 3; do Scripts/dev-server.sh invite "ui-test" | awk '/^ *token:/ {print $2}' >> "$DIR/invites.txt"; done23  printf 'name,url,username,password,note\nImported Shop,https://shop.example.org,ada,123456,\nImported Forum,https://forum.example.org,ada,123456,\nOld Router,http://192.168.1.1,admin,admin,\nImported Bank,https://bank2.example.org,ada,Tr0ub4dor&3-horse-staple-91,\n' > "$DIR/import.csv"24  xcodegen generate --quiet || exit 125}26report() { sed 's/\x1b\[[0-9;]*m//g' "$1" | grep -E "Test Case .*(passed|failed)|error:|Executed [0-9]+ tests?|\*\* TEST|BUILD FAILED|Testing failed" | sed -E "s#$PWD/##" | cut -c1-420 | awk '!seen[$0]++' | tail -"${SPV_LINES:-30}"; }27run() { # scheme, destination, log, only-testing…28  local scheme="$1" dest="$2" log="$3"; shift 329  TEST_RUNNER_SPV_UI_DIR="$DIR" TEST_RUNNER_SPV_UI_SHOTS="$SHOTS" TEST_RUNNER_SPV_UI_PAIR_WITH="${PAIR_WITH:-mac}" \30    xcodebuild -project SPVault.xcodeproj -scheme "$scheme" -configuration Debug -destination "$dest" -derivedDataPath "$DD" "${ACTION:-test}" "$@" > "$log" 2>&131  local s=$?; report "$log"; echo "log: $log"; return $s32}33mac()    { run SPVault "platform=macOS" build/logs/ui-mac.log -only-testing:SPVaultUITests/JourneyTests/test01_JoinAndItemLifecycle -only-testing:SPVaultUITests/JourneyTests/test02_ImportAndSecurityCenter -only-testing:SPVaultUITests/JourneyTests/test03_RecoverOnFreshInstall -only-testing:SPVaultUITests/JourneyTests/test05_AppearanceAndMenuBar; }34iphone() { run SPVault-iOS "platform=iOS Simulator,id=$(sim "SPVault iPhone")" build/logs/ui-iphone.log -only-testing:SPVaultUITests-iOS/JourneyTests/test01_JoinAndItemLifecycle -only-testing:SPVaultUITests-iOS/JourneyTests/test02_ImportAndSecurityCenter -only-testing:SPVaultUITests-iOS/JourneyTests/test03_RecoverOnFreshInstall; }35ipad()   { run SPVault-iOS "platform=iOS Simulator,id=$(sim "SPVault iPad")" build/logs/ui-ipad.log -only-testing:SPVaultUITests-iOS/JourneyTests/test04_SplitLayoutScreenshot; }36pair() {37  rm -f "$DIR/pairing.txt" "$DIR/paired.txt" "$DIR/trusted-wrote.txt"38  # build both test bundles first so that the two runs only read DerivedData while they execute side by side39  ACTION=build-for-testing run SPVault-iOS "platform=iOS Simulator,id=$(sim "SPVault iPhone")" build/logs/ui-pair-build-ios.log >/dev/null || { echo "iOS build-for-testing failed"; return 1; }40  ACTION=build-for-testing run SPVault "platform=macOS" build/logs/ui-pair-build-mac.log >/dev/null || { echo "macOS build-for-testing failed"; return 1; }41  ( ACTION=test-without-building run SPVault-iOS "platform=iOS Simulator,id=$(sim "SPVault iPhone")" build/logs/ui-pair-iphone.log -only-testing:SPVaultUITests-iOS/JourneyTests/test11_PairAsNewDeviceAndSync ) &42  local bg=$!43  ACTION=test-without-building run SPVault "platform=macOS" build/logs/ui-pair-mac.log -only-testing:SPVaultUITests/JourneyTests/test10_ApproveNewDeviceAndSync; local a=$?44  wait $bg; local b=$?45  return $(( a || b ))46}47case "${1:-}" in48  mac|iphone|ipad) prepare; "$1" ;;49  pair) Scripts/dev-server.sh up || exit 1; xcodegen generate --quiet; pair ;;50  one) # one <mac|iphone|ipad> <test name>   — a single journey (debugging)51    prepare52    case "$2" in53      mac) run SPVault "platform=macOS" build/logs/ui-one.log "-only-testing:SPVaultUITests/$3" ;;54      iphone) run SPVault-iOS "platform=iOS Simulator,id=$(sim "SPVault iPhone")" build/logs/ui-one.log "-only-testing:SPVaultUITests-iOS/$3" ;;55      ipad) run SPVault-iOS "platform=iOS Simulator,id=$(sim "SPVault iPad")" build/logs/ui-one.log "-only-testing:SPVaultUITests-iOS/$3" ;;56    esac ;;57  all) prepare; mac; A=$?; iphone; B=$?; ipad; C=$?; pair; D=$?; exit $(( A || B || C || D )) ;;58  *) echo "usage: $0 mac|iphone|ipad|pair|all | one <mac|iphone|ipad> <test>"; exit 2 ;;59esac60
Files main
Menu

Theme