How can I set accessibilityIdentifier to UIAlertController?

前端 未结 4 1638
梦毁少年i
梦毁少年i 2021-02-05 05:56

This is how I simply create UIAlertController and present it on the screen:

private class func showAlertWithTitle(title: String, message: String) {
         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 06:38

    This is an old thread but someone might use this.

    I was able to set the accessibility identifier like this:

    let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
    alert.view.accessibilityIdentifier = "custom_alert"
    alert.view.accessibilityValue = "\(title)-\(message)"
    
    alert.addAction(
        UIAlertAction(
            title: "ALERT_BUTTON_OK".localized,
            style: .default,
            handler: handler
        )
    )
    
    present(alert, animated: true)
    

    That way I can access the alert by accessibility identifier and check its contents in accessibility value.

    It is not perfect of course, but it works - at least for my testing using Appium.

提交回复
热议问题