首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解除警报XCUITest

解除警报XCUITest
EN

Stack Overflow用户
提问于 2016-11-03 14:15:12
回答 3查看 6.5K关注 0票数 4

我试图在我的XCUITest套件中取消警报,我目前正在使用

代码语言:javascript
复制
app.alerts.buttons["OK"].tap()

使用此方法可以解除警报,但是应用程序继续尝试点击按钮,然后失败,错误消息是"UI测试失败-没有找到警报的匹配“。

这是控制台输出

代码语言:javascript
复制
 t =     0.00s     Start Test at 2016-11-03 14:07:30.827
t =     0.00s     Set Up
t =     0.00s         Launch uk.co.myapp
t =     4.89s             Waiting for accessibility to load
t =    12.55s             Wait for app to idle
t =    18.46s         Snapshot accessibility hierarchy for uk.co.myapp
t =    19.24s         Find: Descendants matching type Button
t =    19.25s         Find: Elements matching predicate '"Enable notifications" IN identifiers'
t =    19.26s         Tap "Enable notifications" Button
t =    19.26s             Wait for app to idle
t =    19.40s             Find the "Enable notifications" Button
t =    19.40s                 Snapshot accessibility hierarchy for uk.co.myapp
t =    27.43s                 Find: Descendants matching type Button
t =    27.48s                 Find: Elements matching predicate '"Enable notifications" IN identifiers'
t =    27.52s                 Wait for app to idle
t =    27.93s             Synthesize event
t =    28.31s             Wait for app to idle
t =    33.94s         Tap "OK" Button
t =    33.94s             Wait for app to idle
t =    35.19s             Find the "OK" Button
t =    35.20s                 Snapshot accessibility hierarchy for uk.co.myapp
t =    39.68s                 Find: Descendants matching type Alert
t =    39.69s                 Wait for app to idle
t =    39.82s                     App event loop idle notification not received, will attempt to continue.
t =    39.82s                     App animations complete notification not received, will attempt to continue.
t =    39.83s                 Check for UI interruption: Descendants matching type Alert
t =    39.83s                     Snapshot accessibility hierarchy for com.apple.springboard
t =    39.93s                     Find: Descendants matching type Alert
t =    39.94s                 Find the "“VoucherCodes” Would Like to Send You Notifications" Alert
t =    39.94s                     Use cached accessibility hierarchy for com.apple.springboard
t =    39.97s                     Find: Descendants matching type Alert
t =    39.97s                     Find: Identity Binding
t =    39.98s                 Use cached accessibility hierarchy for com.apple.springboard
t =    39.99s                 Find: Descendants matching type Alert
t =    40.00s                 Find: Identity Binding
t =    40.01s                 Find: Descendants matching type Button
t =    40.01s                 Find: Elements matching predicate 'userTestingAttributes CONTAINS "cancel-button"'
t =    40.01s                 Get number of matches for: Descendants matching type Button
t =    40.13s                     Snapshot accessibility hierarchy for com.apple.springboard
t =    40.23s                     Find: Descendants matching type Alert
t =    40.23s                     Find: Identity Binding
t =    40.24s                     Find: Descendants matching type Button
t =    40.24s                 Get all elements bound by accessibility element for: Elements matching predicate 'userTestingAttributes CONTAINS "default-button"'
t =    40.34s                     Snapshot accessibility hierarchy for com.apple.springboard
t =    40.43s                     Find: Descendants matching type Alert
t =    40.45s                     Find: Identity Binding
t =    40.46s                     Find: Descendants matching type Button
t =    40.46s                     Find: Elements matching predicate 'userTestingAttributes CONTAINS "default-button"'
t =    40.47s                 Use cached accessibility hierarchy for com.apple.springboard
t =    40.49s                 Find: Descendants matching type Alert
t =    40.49s                 Find: Identity Binding
t =    40.50s                 Find: Descendants matching type Button
t =    40.50s                 Find: Elements matching predicate 'userTestingAttributes CONTAINS "default-button"'
t =    40.50s                 Find: Identity Binding
t =    40.50s                 Tap "OK" Button
t =    40.50s                     Wait for app to idle
t =    40.61s                         App event loop idle notification not received, will attempt to continue.
t =    40.61s                         App animations complete notification not received, will attempt to continue.
t =    40.62s                     Find the "OK" Button
t =    40.62s                         Snapshot accessibility hierarchy for com.apple.springboard
t =    40.70s                         Find: Descendants matching type Alert
t =    40.71s                         Find: Identity Binding
t =    40.71s                         Find: Descendants matching type Button
t =    40.71s                         Find: Elements matching predicate 'userTestingAttributes CONTAINS "default-button"'
t =    40.72s                         Find: Identity Binding
t =    40.72s                         Wait for app to idle
t =    40.84s                             App event loop idle notification not received, will attempt to continue.
t =    40.84s                             App animations complete notification not received, will attempt to continue.
t =    40.84s                     Synthesize event
t =    41.17s                     Wait for app to idle
t =    41.43s                         App event loop idle notification not received, will attempt to continue.
t =    41.43s                         App animations complete notification not received, will attempt to continue.
t =    41.44s                 Snapshot accessibility hierarchy for com.apple.springboard
t =    41.52s                 Find: Descendants matching type Alert
t =    41.53s                 Find: Identity Binding
t =    41.54s                 Wait for view controller view-did-disappear
t =    42.21s                 Snapshot accessibility hierarchy for uk.co.myapp
t =    45.68s                 Find: Descendants matching type Alert
t =    45.69s                 Wait for app to idle
t =    46.82s                 Find the "OK" Button (retry 1)
t =    46.82s                     Snapshot accessibility hierarchy for 

myapp t= 50.18s查找:后代匹配类型Alert t= 50.19s等待app空闲t= 51.38s查找"OK“按钮(重试2) t= 51.38s快照可访问性层次结构,uk.myapp t= 55.06s查找后代:匹配类型Alert t= 55.06s等待app到空闲t= 55.44s断言失败: signUpSetUp.swift:21: UI测试失败-没有找到警报查询输入的匹配为{(应用程序0x7fb51cf80840:{{0.0,0},{375.0,667.0},标签

有没有更好的办法来解决这个问题?还是有办法解决我哪里出了问题?在这件事上困惑了一段时间!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-11-04 12:15:53

我改进了@ answer 3271402的答案

代码语言:javascript
复制
addUIInterruptionMonitorWithDescription("alert description") { (alert) -> Bool in
    let alertButton = alert.buttons["OK"]
    if alertButton.exists {
        alertButton.tap()
        return true
    }
    return false
}
app.tap()

如果警报存在,只需点击。如果警报没有发生,则返回false,并在点击应用程序和结束后返回。

票数 11
EN

Stack Overflow用户

发布于 2016-11-03 21:12:05

一种方法在XCTest中用于警报处理:

代码语言:javascript
复制
addUIInterruptionMonitorWithDescription("iTunesStoreAlert") { alert in
    alert.buttons["OK"].tap()
    return true
}

你可以把这个放在你的测试开始。或者你在哪里会收到警报

票数 1
EN

Stack Overflow用户

发布于 2022-08-15 21:42:37

请注意,addUIInteruptionMonitorWithDescription方法只能用于正常工作流程之外的警报。每Apple1

重要 当警报或其他模态UI是测试工作流的预期部分时,不要编写UI中断监视器。测试不会使用监视器,因为模态UI没有阻塞测试。一个UI测试只会尝试它的UI中断监视器,如果它需要与之交互以完成测试的元素被来自不相关UI的中断所阻塞。

如果警报是由正常流提供的,则只需使用普通的XCTestCase方法:

代码语言:javascript
复制
 expectation(
     for: NSPredicate("exists == true"),
     evaluatedWith: XCUIApplication().staticTexts["Error Sending Mail"],
     handler: nil) { error in
     // handle failure here
 }

 XCUIApplication().buttons["OK"].tap()

1

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40403805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档