这就是我简单创建的方式UIAlertController
并将其呈现在屏幕上:
private class func showAlertWithTitle(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
//alert.accessibilityLabel = "my string here" //doesnt work
let action = UIAlertAction(title: "OK", style: .Default) { action in
alert.dismissViewControllerAnimated(true, completion: nil)
}
alert.addAction(action)
UIStoryboard.topViewController()?.presentViewController(alert, animated: true, completion: nil)
}
这就是我在下面访问它的方式UITests:
emailAlert = app.alerts["First Name"] //for title "First Name"
但我想设置自定义标识符并通过以下方式访问它firstName
像这样:
emailAlert = app.alerts["firstName"]
是否可以?
这是一个旧线程,但有人可能会使用它。
我能够像这样设置可访问性标识符:
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)
这样我就可以通过可访问性标识符访问警报并在可访问性值中检查其内容。
当然它并不完美,但它有效 - 至少对于我使用 Appium 的测试来说是这样。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)