77 lines
2.9 KiB
Bash
77 lines
2.9 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# Runs the Maestro E2E suite for apps/user-ui — Android only.
|
|
#
|
|
# - loads secrets/defaults from the gitignored e2e/.env (Maestro has no .env support)
|
|
# - always passes --platform android, so it can never target an iOS simulator
|
|
# - falls back to ~/.maestro/bin/maestro when `maestro` isn't on PATH
|
|
#
|
|
# Usage:
|
|
# bash e2e/run.sh # all flows
|
|
# bash e2e/run.sh flows/place-order.yaml # a single flow
|
|
# bash e2e/run.sh --device emulator-5554 # target a specific emulator
|
|
# bash e2e/run.sh --format junit # extra Maestro flags pass through
|
|
set -euo pipefail
|
|
|
|
E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ENV_FILE="$E2E_DIR/.env"
|
|
|
|
if [ -f "$ENV_FILE" ]; then
|
|
# `set -a` exports every variable defined while sourcing.
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
. "$ENV_FILE"
|
|
set +a
|
|
else
|
|
echo "warning: $ENV_FILE not found — copy e2e/.env.example to e2e/.env and fill it in." >&2
|
|
fi
|
|
|
|
MAESTRO_BIN="${MAESTRO_BIN:-maestro}"
|
|
if ! command -v "$MAESTRO_BIN" >/dev/null 2>&1; then
|
|
MAESTRO_BIN="$HOME/.maestro/bin/maestro"
|
|
fi
|
|
|
|
# Allow flow paths relative to e2e/ (e.g. `flows/place-order.yaml`) while
|
|
# running from the repo root. Anything else is forwarded to Maestro as-is.
|
|
TARGET="$E2E_DIR"
|
|
if [ "$#" -gt 0 ]; then
|
|
case "$1" in
|
|
-*) : ;;
|
|
*)
|
|
if [ -e "$E2E_DIR/$1" ]; then
|
|
TARGET="$E2E_DIR/$1"
|
|
shift
|
|
fi
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# Values shared across the admin + user flows in one round. The slot is always
|
|
# created for the 15th of next month, so it is in the future whatever time the
|
|
# suite runs at (the admin pickers are driven with SLOT_DATE_DESC).
|
|
SLOT_DATE_DESC="$(date -v+1m -v15d '+%d %B %Y')"
|
|
SLOT_DELIVERY_LABEL="$(date -v+1m -v15d '+%d %b'), 6:00 PM"
|
|
PRODUCT_NAME="${PRODUCT_NAME:-E2E Test Item $(date '+%d%b-%H%M')}"
|
|
PRODUCT_PRICE="${PRODUCT_PRICE:-499}"
|
|
|
|
# Maestro doesn't read the shell environment — values from .env have to be
|
|
# forwarded explicitly as `-e KEY=VALUE`.
|
|
ENV_ARGS=()
|
|
for key in TEST_IDENTIFIER TEST_PASSWORD ADDRESS_NAME ADDRESS_PHONE ADDRESS_LINE1 \
|
|
ADMIN_NAME ADMIN_PASSWORD PRODUCT_NAME PRODUCT_PRICE \
|
|
SLOT_DATE_DESC SLOT_DELIVERY_LABEL; do
|
|
if [ -n "${!key:-}" ]; then
|
|
ENV_ARGS+=(-e "$key=${!key}")
|
|
fi
|
|
done
|
|
|
|
# Fixture photo for the product-image step. The admin app can only set a product
|
|
# image through expo-image-picker -> the Android Photo Picker, which lists photos
|
|
# already on the device, so make sure one is there (idempotent).
|
|
FIXTURE_SRC="$E2E_DIR/../apps/user-ui/assets/images/icon.png"
|
|
if [ -f "$FIXTURE_SRC" ] && adb devices 2>/dev/null | grep -q "device$"; then
|
|
adb push "$FIXTURE_SRC" /sdcard/Pictures/e2e-test-image.png >/dev/null 2>&1 || true
|
|
adb shell "am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/Pictures/e2e-test-image.png" >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
exec "$MAESTRO_BIN" test "$TARGET" --platform android ${ENV_ARGS[@]+"${ENV_ARGS[@]}"} "$@"
|