This is how i set it in code:
let userBarButtonItem = UIBarButtonItem(image: userIcon,
style: .Plain,
target: self,
action: Selector("userButtonTapped:"))
userBarButtonItem.accessibilityIdentifier = "userBarButtonItem"
And then inside UITestCase
I need to find this using:
XCUIApplication().otherElements["userBarButtonItem"] //doesnt work, and the reason is:
Assertion Failure: UI Testing Failure - No matches found for "userBarButtonItem" Other
Is there a way how to find this for instance using predicate?
This worked for me:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:UIString(@"Sign In") style:UIBarButtonItemStyleDone target:self action:@selector(submitPressed:)];
self.navigationItem.rightBarButtonItem.accessibilityLabel = @"registration-submit-button";
Then I found it via
app.navigationBars.buttons["registration-submit-button"]
UIBarButtonItem
does not implement UIAccessibilityIdentification
, so setting accessibilityIdentifier
doesn't work.
Instead try
userBarButtonItem.accessibilityLabel = "userBarButtonItem"
And then in test case
XCUIApplication().buttons["userBarButtonItem"]
This should work.
UPDATE :
Now UIBarButtonItem does conforms to UIAccessibilityIdentification, so all these not required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With