some_id
some_id

Reputation: 29896

XCode UITests alternative to .StaticText

Is there a way to connect to the attribute rather than the static text for a UI element?

When I record a UI test, I get the following

sidemenuTable.cells.containingType(.StaticText, identifier:"MULTIMEDIA").childrenMatchingType(.StaticText).matchingIdentifier("MULTIMEDIA").elementBoundByIndex(0).tap()

The problem is that the static text changes across targets, and causes the tests to fail. I would like to be able to access an object's properties inside a tableview. E.g. if a custom cell has a property of cellType.

This way the tests are indepenent of the text inside the UI elements.

Upvotes: 0

Views: 1571

Answers (1)

Joe Masilotti
Joe Masilotti

Reputation: 17008

You can use the textLabel shortcut on an element's accessibilityIdentifier. This isn't presented to the user, so you can make it the same regardless of the element's contents.

Production code:

cell.accessibilityIdentifier = "My Cell"

Test code:

let app = XCUIApplication()
app.staticTexts["My Cell"].tap()

Upvotes: 3

Related Questions