Create a new project.
Add a new target by hitting the ‘+’ sign near the bottom.
Add iOS UI Testing Bundle
Edit your scheme
Confirm at testing bundle was added
Open up your test
And insert a break point
Run your test. Hit record and Xcode will record your application press.
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)) }
Leave a Reply