Xcode UI Testing允许系统警报系列

时间:2016-04-20 19:50:39

标签: ios objective-c xcode xcode-ui-testing ui-testing

我有问题,如果我尝试允许系列系统警报,只工作一次,下一次警报不“允许” 我在Google上搜索更多时间,并了解该帖子:(Xcode 7 UI Testing: how to dismiss a series of system alerts in code) 没什么..不行。 这是我当前的代码,首先警告“允许”成功,未检测到下一个警报..

    t =    10.18s                     Find: Descendants matching type Alert
    t =    10.18s                     Find: Identity Binding
    t =    11.19s                     Find the "Allow “MyApp” to access your location while you use the app?" Alert (retry 1)
    t =    11.19s                         Snapshot accessibility hierarchy for com.apple.springboard
    t =    11.26s                         Find: Descendants matching type Alert
    t =    11.26s                         Find: Identity Binding
    t =    12.27s                     Find the "Allow “MyApp” to access your location while you use the app?" Alert (retry 2)
    t =    12.27s                         Snapshot accessibility hierarchy for com.apple.springboard
    t =    12.33s                         Find: Descendants matching type Alert
    t =    12.34s                         Find: Identity Binding
    t =    12.42s                     Assertion Failure: UI Testing Failure - No matches found for "Allow “MyApp” to access your location while you use the app?" Alert
Query input was {(
    Alert 0x7febe8731630: traits: 72057602627862528, {{25.0, 193.0}, {270.0, 182.0}}, label: '“MyApp” Would Like to Send You Notifications'
)}

祝你好运, 伊凡。

UPD:

好的,我找到了解决方案,如何在第一次提醒后,尝试关闭第二个(感谢这个网站:http://www.it1me.com/it-answers?id=32148965&s=Template:Viper&ttl=Xcode+7+UI+Testing%3A+how+to+dismiss+a+series+of+system+alerts+in+code)只需要返回NO。

但另一个问题......

window.location.assign('home.html');

他尝试关闭第三个通知,而不是第二个,当然他没有找到这个系统警报...

2 个答案:

答案 0 :(得分:9)

Create the alert handlers one by one, before the app launches. Also, make sure to tap() anywhere on the app before interacting with the alert. This is a known bug in Xcode.

addUIInterruptionMonitor(withDescription:"First Dialog") { (alert) -> Bool in
    alert.buttons["Allow"].tap()
    return true
}

addUIInterruptionMonitor(withDescription:"Second Dialog") { (alert) -> Bool in
    alert.buttons["Allow"].tap()
    return true
}

addUIInterruptionMonitor(withDescription:"Third Dialog") { (alert) -> Bool in
    alert.buttons["Allow"].tap()
    return true
}

let app = XCUIApplication()
app.launch()

app.tap()
app.tap()
app.tap()

These three taps will fir each alert handler in succession without actually triggering any events in your app. Also note that each interruption handler doesn't specify anything about the alert, only the confirmation button.

答案 1 :(得分:1)

使用For循环迭代可能的系统警报数似乎是代码中最可能的失败案例。将它转换为一个while循环来评估系统警报的存在,因为条件会在视觉上更清晰,涉及更少的总逻辑,并且没有self.possibleSystemAlerts不是正确值的失败条件。

您的整个显示器逻辑也可以被删除。测试将等到应用程序闲置,此时您将收到警报或没有警报。评估其存在与否,与之相互作用或结束循环。