XCTest 应用程序测试和权限警报 [英] XCTest app tests and permissions alerts
问题描述
我正在编写 XCTest 应用程序测试,通过在 UIApplication
rootViewController
上调用 presentViewController
来测试一些 UIViewController
.
I'm writing XCTest app tests that test some UIViewControllers
by calling presentViewController
on the UIApplication
rootViewController
.
这很好用,除了权限对话框.一些 UIViewControllers
使系统弹出诸如摄像头或麦克风访问之类的权限对话框.我不知道如何解雇他们.
This works fine, except for permissions dialogs. Some of the UIViewControllers
make the system pop permissions dialogs for things like camera or microphone access. I'm not sure how to dismiss them.
如果这是一个 UI 测试,我可以使用 addUIInterruptionMonitorWithDescription
和 tap
警报.
If this were a UI test, I could use addUIInterruptionMonitorWithDescription
and tap
the alert away.
但是,我不确定如何进行这项工作.应用测试可以访问 UI 测试功能吗?
However, I'm not sure how to make this work. Can an app test access UI test features?
推荐答案
在 xcode ui 测试中,要访问系统弹出权限对话框,请使用以下代码:
In xcode ui test, to access system pop permissions dialogs, use the below code:
self.addUIInterruptionMonitorWithDescription("your alert text", handler: { (alert) -> Bool in
yourAlertElement.tap()
return true
})
希望这会有所帮助,如果您有任何疑问,请告诉我.
Hope this will help and if you have any confusion, let me know.
这篇关于XCTest 应用程序测试和权限警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!