Files
Cable/shooter.sh
2025-10-13 09:38:22 +02:00

75 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
SCHEME="CableScreenshots"
DEVICE="iPhone 17 Pro Max"
RUNTIME_OS="26.0" # e.g. "18.1". Leave empty to let Xcode pick.
command -v xcparse >/dev/null 2>&1 || {
echo "xcparse not found. Install with: brew install chargepoint/xcparse/xcparse" >&2
exit 1
}
# Resolve a simulator UDID for the given device name and optional OS (e.g., 18.1)
resolve_udid() {
local name="$1"; local os="$2"
if [[ -n "$os" ]]; then
# Prefer Shutdown state for a clean start
xcrun simctl list devices | awk -v n="$name" -v o="$os" -F '[()]' \
'$0 ~ n && $0 ~ o && /Shutdown/ {print $2; exit}'
else
xcrun simctl list devices | awk -v n="$name" -F '[()]' \
'$0 ~ n && /Shutdown/ {print $2; exit}'
fi
}
for lang in de fr en es nl; do
# Erase all content and settings to ensure a clean simulator state
echo "Resetting simulator for a clean start..."
UDID=$(resolve_udid "$DEVICE" "$RUNTIME_OS")
if [[ -z "$UDID" ]]; then
# Fallback: pick any matching (booted or shutdown)
UDID=$(xcrun simctl list devices | awk -v n="$DEVICE" -F '[()]' '$0 ~ n {print $2; exit}')
fi
if [[ -z "$UDID" ]]; then
echo "Could not resolve UDID for $DEVICE" >&2; exit 1
fi
# Ensure the device is not booted, then fully erase it. Do NOT ignore failures here.
xcrun simctl shutdown "$UDID" || true
xcrun simctl erase "$UDID"
echo "Running screenshots for $lang"
region=$(echo "$lang" | tr '[:lower:]' '[:upper:]')
# Resolve simulator UDID and enforce system language/locale on the simulator itself
UDID=$(resolve_udid "$DEVICE" "$RUNTIME_OS")
if [[ -z "$UDID" ]]; then
# Fallback: pick any matching (booted or shutdown)
UDID=$(xcrun simctl list devices | awk -v n="$DEVICE" -F '[()]' '$0 ~ n {print $2; exit}')
fi
if [[ -z "$UDID" ]]; then
echo "Could not resolve UDID for $DEVICE" >&2; exit 1
fi
# Boot, set system language & locale, then restart the simulator to ensure it sticks
xcrun simctl boot "$UDID" || true
xcrun simctl spawn "$UDID" defaults write 'Apple Global Domain' AppleLanguages -array "$lang"
xcrun simctl spawn "$UDID" defaults write 'Apple Global Domain' AppleLocale "${lang}_${region}"
# Some versions require a reboot of the sim for language changes to fully apply
xcrun simctl shutdown "$UDID" || true
xcrun simctl boot "$UDID"
bundle="results-$lang.xcresult"
outdir="Shots/Screenshots/$lang"
rm -rf "$bundle" "$outdir"
mkdir -p "$outdir"
# Note: Simulator system language/locale is enforced via simctl (AppleLanguages/AppleLocale) before each run.
xcodebuild test \
-scheme "$SCHEME" \
-destination "id=$UDID" \
-resultBundlePath "$bundle"
xcparse screenshots "$bundle" "$outdir"
echo "Exported screenshots to $outdir"
xcrun simctl shutdown "$UDID" || true
done