UITest 中断处理程序调用 tap() 两次

Posted

技术标签:

【中文标题】UITest 中断处理程序调用 tap() 两次【英文标题】:UITest interruption handler calling tap() twice 【发布时间】:2019-11-21 12:38:10 【问题描述】:

我的 UITest 需要点击一个按钮,并且 UIInteruptionMonitor 应该处理它。但是,发生的情况是按钮被点击,中断出现并得到处理,然后它尝试再次点击按钮。它似乎认为它实际上并没有点击按钮......

我有以下代码:

addUIInterruptionMonitor(withDescription: "Permissions")  alert -> Bool in
    let okButton = alert.buttons["OK"]
    if okButton.exists 
      okButton.tap()
    

    return true


app.buttons["Enable"].tap()

会发生以下情况:

t =    91.24s     Find the "Enable" Button
    t =    91.40s     Check for interrupting elements affecting "Enable" Button
    t =    91.42s         Wait for com.apple.springboard to idle
    t =    91.85s     Found 1 interrupting element:
    t =    91.86s         Find the "“MyApp” Would Like to Access the Camera" Alert
    t =    92.03s         "“MyApp” Would Like to Access the Camera" Alert from Application 'com.apple.springboard'
    t =    92.03s     Invoking UI interruption monitors for "“MyApp” Would Like to Access the Camera" Alert from Application 'com.apple.springboard'
    t =    92.03s         Invoking Permissions
    t =    92.04s             Checking existence of `"OK" Button`
    t =    92.21s             Tap "OK" Button
    t =    92.21s                 Wait for com.apple.springboard to idle
    t =    92.50s                 Find the "OK" Button
    t =    92.66s                 Check for interrupting elements affecting "OK" Button
    t =    92.82s                 Synthesize event
    t =    93.14s                 Wait for com.apple.springboard to idle
    t =    93.54s         Verifying handling...
    t =    93.54s             Check for interrupting elements affecting "Enable" Button
    t =    93.55s                 Wait for com.apple.springboard to idle
    t =    94.10s         Confirmed successful handling of interrupting element
    t =    94.10s     Synthesize event
    t =    95.39s         Scroll element to visible
    t =    96.55s         Failed: Failed to scroll to visible (by AX action) Button, label: 'Enable', error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 62934, elementOrHash.elementID: 140664883255456.613
    t =    97.57s     Retrying `Tap "Enable" Button` (attempt #2)

【问题讨论】:

【参考方案1】:

这是正常的。当被系统警报中断时,无法执行预期的操作,因此在成功处理中断后重试。

更一般地,你必须在处理程序中检查你是否成功处理了中断(例如你找到了确定按钮并可以点击它),否则你必须返回 false。

【讨论】:

以上是关于UITest 中断处理程序调用 tap() 两次的主要内容,如果未能解决你的问题,请参考以下文章

UITest tap 在使用 iPhone X 的 iOS 12.4 上不起作用(适用于 iPhone 7)

如何阻止我的 Xamarin.UITest 两次运行测试?

tap点击一次,内部程序执行两次,多次

每次都没有调用中断

将光标放在 UITest 下 UITextView 的末尾

如何使用 UITest 和 Swift 3 单击编辑菜单