Repository Public BSD-3-Clause
1#!/usr/bin/env bash2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : ORIX Maps8# File : scripts/uitest.sh9# Module : scripts10# Repository : https://git.spboucher.ai/orix-maps11# Created : 2026-11-2512# Last Modified : 2026-11-2513#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: support@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# License : Proprietary, all rights reserved (see license file)32# License File : LICENSE33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# ORIX Maps — end-to-end UI tests on the simulator.42#43# usage: scripts/uitest.sh [iphone|ipad] [--screenshots] [xcodebuild test options…]44# scripts/uitest.sh every UI test on "ORIXMaps iPhone"45# scripts/uitest.sh ipad the iPad suite (layout, main flows, screenshots) on "ORIXMaps iPad"46# scripts/uitest.sh iphone -only-testing:ORIXMapsUITests/SearchTests47# scripts/uitest.sh iphone --screenshots -only-testing:ORIXMapsUITests/ScreenshotTour48# also copies the captures named "docs-<name>" to docs/screenshots/<name>.png49#50# What it does: checks the development distribution (data/dev-dist), starts the local map servers that are not already51# running (8765 unthrottled, 8766 throttled; nothing on 8799, the "stopped server"), boots the simulator and waits for52# it, grants the position permission and sets the position downtown Montréal, runs the tests one at a time53# (scripts/build.sh uitest) in three phases — light appearance, dark appearance (audit and screenshot tours), position54# permission revoked — and exports the attachments (screenshots) of each result to build/results/. Servers started55# here are stopped at the end, by PID. ORIX_APPEARANCE=dark runs a selection in the dark appearance.56set -euo pipefail57ROOT="$(cd "$(dirname "$0")/.." && pwd)"58BUNDLE=ai.spboucher.orix.maps59DIST="$ROOT/data/dev-dist"60PORT="${ORIX_PORT:-8765}"; THROTTLED_PORT="${ORIX_THROTTLED_PORT:-8766}"; STOPPED_PORT="${ORIX_STOPPED_PORT:-8799}"61THROTTLE="${ORIX_THROTTLE:-6000000}" # bytes per second: the 222 MB test region takes about 37 s62mkdir -p "$ROOT/build/logs" "$ROOT/build/results"6364device=iphone; screenshots=0; options=()65for a in "$@"; do66 case "$a" in67 iphone|ipad) device="$a" ;;68 --screenshots) screenshots=1 ;;69 *) options+=("$a") ;;70 esac71done72if [ "$device" = ipad ]; then73 export ORIX_SIM="${ORIX_SIM:-ORIXMaps iPad}" ORIX_SIM_TYPE="${ORIX_SIM_TYPE:-iPad Pro 11-inch (M5)}"74else75 export ORIX_SIM="${ORIX_SIM:-ORIXMaps iPhone}" ORIX_SIM_TYPE="${ORIX_SIM_TYPE:-iPhone 17 Pro}"76fi7778[ -f "$DIST/catalog.json" ] || { echo "uitest: no development distribution at data/dev-dist (see Infrastructure/distribution)"; exit 2; }7980started=()81cleanup() { for pid in ${started[@]+"${started[@]}"}; do kill "$pid" 2>/dev/null || true; done; }82trap cleanup EXIT8384listening() { lsof -nP -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1; }85answers() { curl -fsS -o /dev/null --max-time 3 "http://127.0.0.1:$1/maps/v1/catalog.json"; }86serve() { # serve <port> [dev-server options…]87 local port="$1"; shift88 if listening "$port"; then89 answers "$port" || { echo "uitest: port $port is in use by something that is not the map server"; exit 2; }90 echo "uitest: using the map server already listening on $port"91 return92 fi93 python3 "$ROOT/Infrastructure/distribution/dev-server.py" "$DIST" "$port" "$@" > "$ROOT/build/logs/dev-server-$port.log" 2>&1 &94 started+=("$!")95 for _ in $(seq 1 50); do answers "$port" 2>/dev/null && { echo "uitest: started the map server on $port (pid $!)"; return; }; sleep 0.1; done96 echo "uitest: the map server did not start on $port (build/logs/dev-server-$port.log)"; exit 297}98serve "$PORT"99serve "$THROTTLED_PORT" --throttle "$THROTTLE"100if listening "$STOPPED_PORT"; then echo "uitest: port $STOPPED_PORT must be free (it plays the stopped server)"; exit 2; fi101export TEST_RUNNER_ORIX_CATALOG_URL="http://127.0.0.1:$PORT/maps/v1/"102export TEST_RUNNER_ORIX_THROTTLED_CATALOG_URL="http://127.0.0.1:$THROTTLED_PORT/maps/v1/"103export TEST_RUNNER_ORIX_STOPPED_CATALOG_URL="http://127.0.0.1:$STOPPED_PORT/maps/v1/"104105# Simulator: created on first use, booted, and ready before anything is launched.106id=$(xcrun simctl list devices available | grep -F "$ORIX_SIM (" | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/' || true)107if [ -z "$id" ]; then id=$(xcrun simctl create "$ORIX_SIM" "$ORIX_SIM_TYPE"); echo "uitest: created the simulator $ORIX_SIM ($ORIX_SIM_TYPE)"; fi108xcrun simctl bootstatus "$id" -b >/dev/null109xcrun simctl ui "$id" content_size large110xcrun simctl location "$id" set 45.5017,-73.5673111echo "uitest: $ORIX_SIM — $(xcrun simctl list devices | grep -F "$id" | sed -E 's/^ +//') — $(xcrun simctl getenv "$id" SIMULATOR_RUNTIME_VERSION 2>/dev/null || true)"112113# The position permission can only be granted to an installed application: on a new simulator, build and install it first.114if ! xcrun simctl get_app_container "$id" "$BUNDLE" >/dev/null 2>&1; then115 "$ROOT/scripts/build.sh" debug >/dev/null116 xcrun simctl install "$id" "$ROOT/build/DerivedData/Build/Products/Debug-iphonesimulator/ORIXMaps.app"117 echo "uitest: installed the application on $ORIX_SIM"118fi119120status=0121run() { # run <result name> <xcodebuild options…>122 local name="$1"; shift123 ORIX_RESULT_NAME="$name" "$ROOT/scripts/build.sh" uitest "$@" || status=1124 local out="$ROOT/build/results/$name-attachments"125 rm -rf "$out"126 xcrun xcresulttool export attachments --path "$ROOT/build/results/$name.xcresult" --output-path "$out" >/dev/null 2>&1 || true127 if [ "$screenshots" = 1 ] && [ -f "$out/manifest.json" ]; then python3 "$ROOT/scripts/collect-screenshots.py" "$out" "$ROOT/docs/screenshots"; fi128}129130selected=0131for o in ${options[@]+"${options[@]}"}; do case "$o" in -only-testing:*) selected=1 ;; esac; done132# On this simulator runtime a change of appearance is only rendered after a restart of the simulator: set it, restart,133# wait, and put the position back.134appearance() {135 xcrun simctl ui "$id" appearance "$1"136 xcrun simctl shutdown "$id" >/dev/null 2>&1 || true137 xcrun simctl boot "$id"138 xcrun simctl bootstatus "$id" -b >/dev/null139 sleep 20 # the first UI queries after a restart time out while the system is still settling140 xcrun simctl location "$id" set 45.5017,-73.5673141 export TEST_RUNNER_ORIX_APPEARANCE="$1"142}143DARK=(-only-testing:ORIXMapsUITests/AccessibilityTests/testAuditDark -only-testing:ORIXMapsUITests/ScreenshotTour/testEnglishDark -only-testing:ORIXMapsUITests/ScreenshotTour/testFrenchDark)144145appearance light146if [ "$selected" = 1 ]; then147 # A selection: run it as asked. Position-refused tests need the permission revoked first; ORIX_APPEARANCE=dark148 # runs the selection with the simulator in its dark appearance (the *Dark tests run only then).149 case " ${options[*]} " in150 *LocationDeniedTests*) xcrun simctl privacy "$id" revoke location "$BUNDLE" ;;151 *) xcrun simctl privacy "$id" grant location "$BUNDLE" ;;152 esac153 appearance "${ORIX_APPEARANCE:-light}"154 run "uitest-$device" "${options[@]}"155 appearance light156 xcrun simctl privacy "$id" grant location "$BUNDLE"157elif [ "$device" = ipad ]; then158 xcrun simctl privacy "$id" grant location "$BUNDLE"159 run "uitest-ipad" -only-testing:ORIXMapsUITests/PadTests -only-testing:ORIXMapsUITests/ScreenshotTour160 appearance dark161 run "uitest-ipad-dark" -only-testing:ORIXMapsUITests/ScreenshotTour/testEnglishDark -only-testing:ORIXMapsUITests/ScreenshotTour/testFrenchDark162 appearance light163else164 # 1. Light appearance, position allowed: everything but the tests of the other phases (which skip themselves).165 xcrun simctl privacy "$id" grant location "$BUNDLE"166 run "uitest-iphone" -skip-testing:ORIXMapsUITests/LocationDeniedTests -skip-testing:ORIXMapsUITests/PadTests167 # 2. Dark appearance: the accessibility audit and the screenshot tours in dark.168 appearance dark169 run "uitest-iphone-dark" "${DARK[@]}"170 appearance light171 # 3. Position refused.172 xcrun simctl privacy "$id" revoke location "$BUNDLE"173 run "uitest-iphone-denied" -only-testing:ORIXMapsUITests/LocationDeniedTests174 xcrun simctl privacy "$id" grant location "$BUNDLE"175fi176echo "uitest: results in build/results/ (logs in build/logs/)"177exit $status178