【问题标题】:How to acknowledge system alerts on a device with KIF testing framework?如何在具有 KIF 测试框架的设备上确认系统警报?
【发布时间】:2018-09-16 15:33:18
【问题描述】:

我从this 帖子中使用这行代码了解了如何在模拟器上确认系统警报:

self.viewTester.acknowledgeSystemAlert()

不幸的是,KIF 代码包含#if TARGET_IPHONE_SIMULATOR,因此它无法在设备上运行。如何在自动化测试期间绕过设备上的权限警报?

【问题讨论】:

    标签: ios swift permissions kif


    【解决方案1】:

    我遇到了同样的问题,在这里我找到了解决方案:

    这个 KIF 功能在设备上不起作用,它只适用于模拟器!因此,您可以在 UITarget 中有一个 UITest,而其中只有一个测试用例,它将像这样添加一个 UIMonitors:

    // ask for all the permission from users then : 
       _ = addUIInterruptionMonitor(withDescription: "") { alert -> Bool in
            let confirmLabels = ["Allow", "OK"]
            for (_, label) in confirmLabels.enumerated() {
                let allow = alert.buttons[label]
                if allow.exists {
                    allow.tap()
                    break
                }
            }
    
            return true
        } 
    // do some UI interaction here like tapping on some view in app 
    

    因此,您可以在每次运行 UnitTest 之前调用此 UITest,这将使您的应用准备好获得所有权限。

    顺便说一句,如果有人有更好的解决方案,请提供我也想知道的原因;)

    【讨论】:

      猜你喜欢
      • 2015-07-13
      • 2018-01-14
      • 1970-01-01
      • 2023-03-08
      • 2016-08-13
      • 2019-03-11
      • 1970-01-01
      • 2022-06-23
      • 2019-07-27
      相关资源
      最近更新 更多