Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

app.buttons[""].tap()

When it tries to run the saved UI commands, it obviously chokes on this and crashes the test...is 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.

like image 344
menriquez Avatar asked Oct 22 '25 04:10

menriquez


1 Answers

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

If, on the other hand, there's a timing issue because you need to wait for the element to appear, I recommend Joe Masilotti's blog post about custom helpers in XCUITest: http://masilotti.com/xctest-helpers/

like image 135
Aaron Sofaer Avatar answered Oct 24 '25 18:10

Aaron Sofaer



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!