WWDC25 Record, replay, and review: UI automation with Xcode
Demo XCTest Test Record Code Generation
App
: Main application project folderAppTests
: Contains unit tests for verifying individual components and logicAppUITests
: Contains end-to-end UI tests, maintained by the QA team, for functional testing of the user interfaceElements
: Contains element locators defined in.properties
filesHelpers
: Utility/helper classes for reusable methodsPages
: Page classes that represent screens or views in the applicationTests
: Test classes containing test scenarios and validations
# Run Test
xcodebuild test \
-scheme LoginTests \
-destination 'platform=iOS Simulator,name=iPhone 16,OS=26.0' \
-resultBundlePath TestResults.xcresult
# Open Test Report
open TestResults.xcresult
- You can now record UI flows directly within Xcode. With the test cursor placed inside an XCTest UI method, click “Start Recording” in the gutter.
- Xcode boots the app in simulator and logs every tap, swipe, and button press—then converts them into structured XCTest/XCUIElement calls
- Use Test Plans to run recorded tests on different devices, locales, orientations, and system states—all in one shot
- Xcode supports launches across languages (especially with long strings and RTL layouts), device types, Dark/Light mode, and more
- After tests complete, review passes and failures via the Xcode Test Report.
- Grab video recordings and screenshots for each run. Plus, use the Automation Explorer to replay failures and inspect element-level information—including actual vs. expected element types/tap targets
- Automation Explorer shows exactly where failures happened. For example, if a TextField was actually a TextView, Xcode pinpoints the mistake and even suggests the correct code snippet—no guesswork required
- Generated tests include multiple identifier options. You can fine-tune element locators right in the editor.
- Build Tests by Example: No manual scripting—record and start verifying flows in minutes.
- Ensure Consistency Across Environments: Catch UI bugs early, whether they’re related to language, device type, or orientation.
- Speed Up Debugging: Media playback + UI element inspection = fast root cause analysis.
- Tight Integrations with CI/CD: Pair with Xcode Cloud for automated validation on each PR or nightly build.
✅ Best Practices from the Session
- Prep Your App for Automation: Add accessibility identifiers to UI elements for stable recording
- Organize with Test Plans: Use multiple device and locale configurations to cover your supported matrix in one run
- Refine Locators Post-Record: Improve stability by choosing strong identifiers after recording your flow.
Integrating UI functional tests directly into the main iOS development project brings several advantages:
- Faster Feedback Loop: QA engineers can validate new features as soon as they are developed, enabling early detection of UI or behavioral issues.
- Improved Collaboration: Developers and QA work within the same codebase, making it easier to align on test coverage, element identifiers, and test scenarios.
- Version Alignment: Tests are always in sync with the latest app version, reducing risks from mismatches between test and app code.
- Simplified CI/CD Integration: Running functional UI tests as part of the same pipeline ensures automated validation with every build or pull request.
- Better Maintenance: Sharing the same project structure reduces duplication and makes it easier to refactor or update tests alongside app changes.
- Encourages Test-Driven Development (TDD): QA involvement in the same project promotes earlier thinking about testability and behavior expectations.
We leverage Xcode 26’s record and replay feature for streamlined UI test creation:
-
Recording
Place the cursor in a UI test function → click Start Recording → interact with the app → stop recording. Xcode converts actions into XCTest code usingXCUIElement
. -
Replay Across Configurations
Use Test Plans to run recorded tests on multiple devices, locales, orientations, and system conditions in one batch. -
Review with Media
Inspect results with the Test Report: watch video replays, see screenshots, and inspect UI elements to debug unexpected failures. -
Refine & Enhance
Edit locators or add assertions. Recorded code includes multiple identifier options and media support for fast validation.
- Rapid test setup by example
- Multi-device and multi-locale QA coverage
- Direct debugging with recorded UI interactions
- Seamless CI/CD integration via Xcode Cloud