【问题标题】:Dismissing alert XCUITest解除警报 XCUITest
【发布时间】:2017-03-17 04:10:13
【问题描述】:

我正在尝试关闭我的 XCUITest 套件上的警报,我目前正在使用

app.alerts.buttons["OK"].tap()

使用此选项会关闭警报,但随后应用程序继续尝试点击按钮,然后失败并显示错误消息“UI TESTING FAILURE - No matches found for alert

这是控制台输出

 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 

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

有没有更好的方法来解决这个问题?或者有什么办法可以解决我出错的地方吗?对此困惑了一段时间!

【问题讨论】:

    标签: swift xcode xcode7 xcode-ui-testing


    【解决方案1】:

    我改进了@user3271402的答案

    addUIInterruptionMonitorWithDescription("alert description") { (alert) -> Bool in
        let alertButton = alert.buttons["OK"]
        if alertButton.exists {
            alertButton.tap()
            return true
        }
        return false
    }
    app.tap()
    

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

    【讨论】:

    • app.tap() 至关重要。不要错过。
    • 太棒了!你节省了我的时间:D
    【解决方案2】:

    XCTest 中有a method 用于警报处理:

    addUIInterruptionMonitorWithDescription("iTunesStoreAlert") { alert in
        alert.buttons["OK"].tap()
        return true
    }
    

    你可以把它放在你的测试开始......或者你应该收到警报的地方

    【讨论】:

      猜你喜欢
      • 2018-05-01
      • 1970-01-01
      • 2017-09-04
      • 2012-07-26
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多