UITests in Xcode 7 finds the wrong Next button

I have a test that looks like this:

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

This test fails because, in addition to my own Next button that I created, the return button to the keyboard is marked as Next. This test failed with the error:

UI Test Error - Multiple Matches Found

How can I distinguish between my own Next button and the Next button on my keyboard?

+6
source share
1 answer

A specific solution to this problem is to search 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 such problems: In Xcode, run the β€œRecord UI Test” again to find out how Xcode thinks you should refer to the element you are interested in.

+8
source

All Articles