作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
这就是我如何简单地创建 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 进行的测试而言。
关于ios - 如何将 accessibilityIdentifier 设置为 UIAlertController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38117410/
我是一名优秀的程序员,十分优秀!