Skip to content

Instantly share code, notes, and snippets.

@triztian
Last active April 17, 2025 11:38
Show Gist options
  • Save triztian/34454ef35ff5d9262e10fe6de49b408b to your computer and use it in GitHub Desktop.
Save triztian/34454ef35ff5d9262e10fe6de49b408b to your computer and use it in GitHub Desktop.
A script to run clean parallel iOS UI Tests
#!/bin/zsh
# run_uitests_parallel.sh
# ParallelUITests
#
# Created by Tristian Azuara on 9/13/20.
set -e
device_name="CI UI Parallel"
echo "=> 1. Creating new device: '$device_name'"
device_udid=$(xcrun simctl create "$device_name" "iPhone 8")
echo "=> Created new device: '$device_name' $device_udid"
echo "=> 2. Disabling Hardware Keyboard for: $device_udid"
alias plist=/usr/libexec/PlistBuddy
simprefs="$HOME/Library/Preferences/com.apple.iphonesimulator.plist"
plist -c "Set :DevicePreferences:$device_udid:ConnectHardwareKeyboard true" "$simprefs" \
|| plist -c "Add :DevicePreferences:$device_udid:ConnectHardwareKeyboard bool true" "$simprefs";
BUILD_DIR=$(mktemp -d)
SYMROOT="$BUILD_DIR"
echo "=> 3. Building for Testing: "
echo "=> Build Directory: $BUILD_DIR"
xcodebuild build-for-testing \
-project ./ParallelUITests.xcodeproj -scheme ParallelUITests \
-destination "platform=iOS Simulator,id=$device_udid" \
SYMROOT=$BUILD_DIR \
BUILD_DIR=$BUILD_DIR
echo "=> 4. Pre-booting Source Device: $device_udid"
xcrun simctl boot $device_udid
xcrun simctl bootstatus $device_udid && sleep 2
testrun=$(find "$BUILD_DIR" -name '*Parallel UI Tests*.xctestrun')
echo "=> Found Test Run File: $testrun"
result_bundle="$BUILD_DIR/$device_name.xcresult"
echo "=> Result Bundle: $result_bundle"
echo "=> 5. Running Tests (Parallel)"
xcodebuild test-without-building \
-destination "platform=iOS Simulator,id=$device_udid" \
-xctestrun "$testrun" \
-resultBundlePath "$result_bundle"
echo "=> 6. Archiving Results"
bundle_name=$(basename "$result_bundle")
cd $(dirname "$result_bundle")
zip -r "$bundle_name.zip" "$bundle_name"
@pvroosendaal
Copy link

I stumbled upon this gist while searching for a solution with the hardware keyboard connect setting while running (parallel) UI tests in a CI pipeline with Xcode 16.1 and iPhone 14/iOS 17.5 simulator... Aren't you actually enabling the hardware keyboard connect setting on line 18-19 in stead of disabled like the echo statement on line 14 suggests (and also your Medium article)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment