Skip to content

Commit 1a7feb5

Browse files
committed
Ugh
1 parent b14f558 commit 1a7feb5

File tree

1 file changed

+72
-18
lines changed

1 file changed

+72
-18
lines changed

scripts/run-ios-ui-tests.sh

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,35 +160,96 @@ else
160160
ri_log "Scheme file not found for env injection: $SCHEME_FILE"
161161
fi
162162

163-
# Derive desired simulator OS from SDKROOT (e.g., iphonesimulator18.5 -> 18 / 5)
164-
SDKROOT_OS="${SDKROOT#iphonesimulator}"
165-
DESIRED_OS_MAJOR="${SDKROOT_OS%%.*}"
166-
DESIRED_OS_MINOR="${SDKROOT_OS#*.}"; [ "$DESIRED_OS_MINOR" = "$SDKROOT_OS" ] && DESIRED_OS_MINOR=""
163+
# --- begin: pick latest available iOS runtime + an iPhone device type (JSON-based) ---
164+
require_cmd() { command -v "$1" >/dev/null 2>&1 || { ri_log "FATAL: '$1' not found"; exit 3; }; }
165+
require_cmd xcrun
166+
require_cmd python3
167+
168+
# Allow manual override from env if you want to pin a specific runtime/device on a given runner:
169+
# IOS_RUNTIME_ID="com.apple.CoreSimulator.SimRuntime.iOS-18-5"
170+
# IOS_DEVICE_TYPE="com.apple.CoreSimulator.SimDeviceType.iPhone-16"
171+
RUNTIME_ID="${IOS_RUNTIME_ID:-}"
172+
DEVICE_TYPE="${IOS_DEVICE_TYPE:-}"
167173

168-
# Determine an iOS 18 runtime and create a throwaway iPhone 16 device
169-
RUNTIME_ID="$(xcrun simctl list runtimes | awk '/iOS 18\./ && $0 ~ /Available/ {print $NF; exit}')"
170174
if [ -z "$RUNTIME_ID" ]; then
171-
ri_log "FATAL: No iOS 18.x simulator runtime available"
175+
RUNTIME_ID="$(xcrun simctl list runtimes --json 2>/dev/null | python3 - <<'PY'
176+
import json, sys
177+
try:
178+
data=json.load(sys.stdin)
179+
except Exception:
180+
sys.exit(1)
181+
c=[]
182+
for r in data.get("runtimes", []):
183+
# Newer Xcodes use platform == "iOS"; older had name strings. Check both.
184+
plat = r.get("platform") or r.get("name","")
185+
if "iOS" not in str(plat): continue
186+
if not r.get("isAvailable", False): continue
187+
ident = r.get("identifier") or ""
188+
ver = r.get("version") or ""
189+
# Turn version into a sortable tuple
190+
parts=[]
191+
for p in str(ver).split("."):
192+
try: parts.append(int(p))
193+
except: parts.append(0)
194+
c.append((parts, ident))
195+
if not c:
196+
sys.exit(2)
197+
c.sort()
198+
print(c[-1][1])
199+
PY
200+
)"
201+
fi
202+
203+
if [ -z "$RUNTIME_ID" ]; then
204+
ri_log "FATAL: No *available* iOS simulator runtime found on this runner"
205+
xcrun simctl list runtimes || true
172206
exit 3
173207
fi
174-
DEVICE_TYPE="com.apple.CoreSimulator.SimDeviceType.iPhone-16"
208+
209+
if [ -z "$DEVICE_TYPE" ]; then
210+
DEVICE_TYPE="$(xcrun simctl list devicetypes --json 2>/dev/null | python3 - <<'PY'
211+
import json, sys
212+
try:
213+
data=json.load(sys.stdin)
214+
except Exception:
215+
sys.exit(1)
216+
dts=data.get("devicetypes",[])
217+
# prefer newest iPhone names if present, else any iPhone, else first available
218+
prefs = ["iPhone 16 Pro Max","iPhone 16 Pro","iPhone 16","iPhone 15 Pro Max","iPhone 15 Pro","iPhone 15","iPhone"]
219+
for pref in prefs:
220+
for dt in dts:
221+
if pref in (dt.get("name") or ""):
222+
print(dt.get("identifier","")); sys.exit(0)
223+
if dts:
224+
print(dts[0].get("identifier","")); sys.exit(0)
225+
sys.exit(2)
226+
PY
227+
)"
228+
fi
229+
230+
if [ -z "$DEVICE_TYPE" ]; then
231+
ri_log "FATAL: Could not determine an iPhone device type"
232+
xcrun simctl list devicetypes || true
233+
exit 3
234+
fi
235+
175236
SIM_NAME="CN1 UI Test iPhone"
176237
SIM_UDID="$(xcrun simctl create "$SIM_NAME" "$DEVICE_TYPE" "$RUNTIME_ID" 2>/dev/null || true)"
177238
if [ -z "$SIM_UDID" ]; then
178-
ri_log "FATAL: Failed to create simulator ($DEVICE_TYPE, $RUNTIME_ID)"
239+
ri_log "FATAL: Failed to create simulator (deviceType=$DEVICE_TYPE, runtime=$RUNTIME_ID)"
179240
exit 3
180241
fi
181242
SIM_UDID_CREATED="$SIM_UDID"
182-
ri_log "Created simulator $SIM_NAME ($SIM_UDID) with runtime $RUNTIME_ID"
243+
ri_log "Created simulator $SIM_NAME ($SIM_UDID) deviceType=$DEVICE_TYPE runtime=$RUNTIME_ID"
183244

184-
# Boot it and wait until it's ready
185245
xcrun simctl boot "$SIM_UDID" >/dev/null 2>&1 || true
186246
if ! xcrun simctl bootstatus "$SIM_UDID" -b -t 180; then
187247
ri_log "FATAL: Simulator never reached booted state"
188248
exit 4
189249
fi
190250
ri_log "Simulator booted: $SIM_UDID"
191251
SIM_DESTINATION="id=$SIM_UDID"
252+
# --- end: pick latest available iOS runtime + an iPhone device type (JSON-based) ---
192253

193254
ri_log "Running UI tests on destination '$SIM_DESTINATION'"
194255

@@ -297,13 +358,6 @@ if [ -n "$AUT_APP" ] && [ -d "$AUT_APP" ]; then
297358
fi
298359

299360
# Run only the UI test bundle
300-
# --- Begin: Start run video recording ---
301-
RUN_VIDEO="$ARTIFACTS_DIR/run.mp4"
302-
ri_log "Recording simulator video to $RUN_VIDEO"
303-
# recordVideo exits only when killed, so background it and store pid
304-
( xcrun simctl io booted recordVideo "$RUN_VIDEO" & echo $! > "$SCREENSHOT_TMP_DIR/video.pid" ) || true
305-
# --- End: Start run video recording ---
306-
307361
UI_TEST_TARGET="${UI_TEST_TARGET:-HelloCodenameOneUITests}"
308362
XCODE_TEST_FILTERS=(
309363
-only-testing:"${UI_TEST_TARGET}"

0 commit comments

Comments
 (0)