UITests in Xcode 7 finds wrong 'Next' button
Asked Answered
B

1

6

I have a test that looks like the following:

func testNextButtonDisabled() {
  let app = XCUIApplication()
  XCTAssertFalse(app.buttons["Next"].enabled)
}

This test fails because, in addition to my own "Next" button that I've created, the keyboard return button is labeled 'Next'. This test fails with the error:

UI Testing Failure - Multiple matches found

How can I differentiate between my own 'Next' button and the keyboard 'Next' button?

Barrybarrymore answered 19/8, 2015 at 20:51 Comment(0)
B
8

The specific solution to this problem is to look for elements that are descendants of the main window.

func testNextButtonDisabled() {
  let app = XCUIApplication()
  XCTAssertFalse(app.childrenMatchingType(.Window).elementBoundByIndex(0).buttons["Next"].enabled)
}

For a general solution to solve problems like this: In Xcode run the "Record UI Test" again to see how Xcode thinks you should be referencing the element in which you're interested.

Barrybarrymore answered 19/8, 2015 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.