Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITests in Xcode 7 finds wrong 'Next' button

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?

like image 959
kubi Avatar asked Aug 19 '15 20:08

kubi


1 Answers

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.

like image 93
kubi Avatar answered Nov 06 '22 01:11

kubi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!