gpt4 book ai didi

xcode7 - XCode 7 UI 测试 : Dismissal of system-generated UIAlertController does not work

转载 作者:行者123 更新时间:2023-12-02 06:59:33 24 4
gpt4 key购买 nike

我有一个 UI 测试,涉及关闭系统生成的 UIAlertController。此警报要求用户授予访问设备日历的权限。测试的目标是点击OK按钮后的行为:

1 let app = XCUIApplication()
...
// this code was basically generated by the recording feature of XCode 7
2 app.alerts.elementBoundByIndex(0).collectionViews.buttons["OK"].tap()

现在,第 2 行不再单击 OK 按钮,而是让模拟器点击第一个按钮,该按钮恰好是 Cancel 按钮...

此外,我发现测试框架无法准确识别出现的警报。因此,如果我检查当前的警报计数,我总是得到 0:

// ...tap...
let count = app.alerts.count // == 0

如果我使用 NSPredicate 作为条件并等待几秒钟,也会发生这种情况。

UI 测试是否可能无法与系统生成的警报一起可靠地工作?我正在使用 XCode 7.0.1。

最佳答案

Xcode 7.1 终于修复了系统警报问题。然而,有两个小问题。

首先,您需要在显示警报之前设置一个“UI 中断处理程序”。这是我们告诉框架如何在警报出现时处理警报的方式。

其次,呈现警报后,您必须与界面进行交互。只需点击应用程序即可正常工作,但这是必需的。

addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
alert.buttons["Allow"].tap()
return true
}

app.buttons["Request Location"].tap()
app.tap() // need to interact with the app for the handler to fire

“位置对话框”只是一个字符串,用于帮助开发人员识别访问了哪个处理程序,它并不特定于警报类型。我相信从处理程序返回 true 将其标记为“完整”,这意味着它不会再次被调用。

关于xcode7 - XCode 7 UI 测试 : Dismissal of system-generated UIAlertController does not work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33124179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com