Xcode UI recording turns a short manual simulator pass into starter XCUIAutomation source. It fits a bounded login, onboarding, purchase, or settings path where the first draft can come from a known-good manual pass.
The recorder writes taps, typing, swipes, and other UI interactions into the XCTest UI test method that has the insertion point. Keep the first recording narrow, because the generated code is meant to be reviewed rather than kept as an untouched capture of every exploratory tap.
A recorded UI test should not be kept until the generated queries are reviewed and at least one XCTest assertion proves the screen state that matters. Stable accessibility identifiers usually make recorded actions less fragile than visible labels that can change with copy, localization, or dynamic content.
Related: How to run XCUITest tests locally
Steps to record an XCUITest UI test in Xcode:
- Open the project in Xcode and select the app scheme with a simulator destination.
- Open a UI test source file and place the cursor inside the test method that should receive the recorded actions.
import XCTest final class LoginUITests: XCTestCase { func testLoginFlow() throws { let app = XCUIApplication() app.launch() } }
The recording target must be a UI test method in a UI testing bundle, not a unit test method.
Related: How to add an XCUITest UI testing target - Click the Start Recording UI Test control in the source editor or recording prompt.
- Wait for Xcode to build the app and launch it in the selected simulator.
- Perform one focused user flow in the simulator.
- Stop the recording from Xcode after the last interaction appears in the test method.
- Review the recorded actions and replace fragile label-based queries with stable accessibility identifiers where the app exposes them.
func testLoginFlow() throws { let app = XCUIApplication() app.launch() app.buttons["loginButton"].tap() app.textFields["emailField"].tap() app.textFields["emailField"].typeText("user@example.com") app.secureTextFields["passwordField"].tap() app.secureTextFields["passwordField"].typeText("example-password") app.buttons["submitButton"].tap() }
Use app-specific identifiers such as loginButton and emailField only when those identifiers exist in the app code.
Related: How to query UI elements in XCUITest - Add an assertion that proves the recorded flow reached the expected screen.
XCTAssertTrue(app.staticTexts["Welcome"].waitForExistence(timeout: 5))
- Run the edited UI test from the test diamond, Product → Test, or the Test navigator.
- Confirm that the Xcode test report shows the edited test as passed.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.