11

First of all yes I have seen this so question but there is currently no answer.

The root problem is that I am currently XCUITesting my app which is localized so the UIAlertActions are localized so I can't find the button.

I could do a hack wherein I'll include all the Localizable.strings on my UITesting bundle then get the localized version when trying to fetch the button like this.

let localizedAlertTitle = ...(some function to fetch localized name)
let localizedButtonName = ...(some function to fetch localized name)
self.app
    .alerts[localizedAlertTitle]
    .buttons[localizedButtonName]
    .tap()

Another way is to probably do the hack said by this so answer but it's too hacky and has boilerplate.

Is there a way to set the accessibilityIdentifier on a UIAlertAction?

Zonily Jame
  • 5,053
  • 3
  • 30
  • 56

1 Answers1

0

I'm not sure what situation was with this in 2018, but nowadays accessibility identifier can be assigned to UIAlertActions (since it conforms to UIAccessibilityIdentification):

let action = UIAlertAction(title: "Title", style: .destructive) { _ in
  // Handle action here.
}
action.accessibilityIdentifier = "ActionIdentifier"

And I have no problems to use in in my UI tests:

app.buttons["ActionIdentifier"]
lazarevzubov
  • 1,767
  • 2
  • 14
  • 24