Create a new project.

Add a new target by hitting the ‘+’ sign near the bottom.

Screen Shot 2018-10-18 at 1.37.17 PM

Add iOS UI Testing Bundle

Screen Shot 2018-10-18 at 1.37.53 PM

Edit your scheme

Screen Shot 2018-10-18 at 1.39.38 PM

Confirm at testing bundle was added

Screen Shot 2018-10-18 at 1.39.50 PM

Open up your test

Screen Shot 2018-10-18 at 1.41.50 PM

And insert a break point

Screen Shot 2018-10-18 at 1.41.56 PM

Run your test. Hit record and Xcode will record your application press.

Screen Shot 2018-10-18 at 1.47.41 PM

Add accessibility to your buttons and controls like this

    let button: UIButton = {
        let button = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        button.backgroundColor = .green
        button.setTitle("GOT IT", for: .normal)
        button.setTitleColor(.black, for: .normal)
        button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)

        button.accessibilityIdentifier = "gotItButton"

        return button
    }()

Sample test

    func testExample() {
        // Use recording to get started writing UI tests.
        // Use XCTAssert and related functions to verify your tests produce the correct results.

        XCUIApplication().buttons["GOT IT"].tap()
        XCTAssertTrue(XCUIApplication().buttons["gotItButton"].waitForExistence(timeout: 10))
    }
Advertisements