menriquez menriquez - 1 year ago 91
iOS Question

Access app.buttons in Xcode UITest without having any usable text for referencing.

So I am trying to get

fastlane screenshot
working and that means getting Xcode UITest working...I build an Ionic app that uses a 3-bar symbol as a slide-out button and that sort of thing is trivial with webapps.

However, when I use uITest record, it misinterprets the button and ends up representing like this


When it tries to run the saved UI commands, it obviously chokes on this and crashes the there any other way to represent the button other then using its label text like that?

It would seem to be that it could use the ID or NAME for the button identifier, but I have yet to find that solution for this problem anywhere.

Answer Source

You can give the button an AccessibilityIdentifier, which is a property that will only be read by the UI Tests and which does not require there to be any readable text.

You can also give the button an AccessibilityLabel, which will enable your button to be used by people who are using accessibility, such as with screen readers or other such devices.

Both of these properties can be read by the XCUIElementQuery, which means you will be able to use, e.g., app.buttons["slide_out"].tap().

In order to do this, you set the accessibilityIdentifier / accessibilityLabel explicitly in code (button.accessibilityIdentifier = "slide_out", for example) or in the Storyboard (under properties; see screenshot).

Here is the Storyboard area in question

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download