首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >自动关闭XCTestCase中的对话框

自动关闭XCTestCase中的对话框
EN

Stack Overflow用户
提问于 2020-07-23 02:47:36
回答 2查看 149关注 0票数 0

当我的应用程序第一次启动时,它会显示一个对话框,要求用户在允许应用程序使用麦克风时单击“不允许”或“确定”进行响应。

问题是,当第一次启动单元测试时,会出现相同的对话框,它会停止测试的执行。如果单元测试是由Xcode Server运行的,则无法手动干预并单击按钮。

有没有一种方法可以自动关闭这个对话框?单击哪个按钮进行单元测试并不重要。

我尝试将以下代码放入XCTestCase setUp()方法中:

代码语言:javascript
运行
复制
[self addUIInterruptionMonitorWithDescription:@"Interruption Monitor" handler:^{BOOL(XCUIElement * element) {
    XCUIElement *button = [[element buttons] elementAtIndex:0];
    if (button) {
        [button tap];
    }
}];

但是处理程序从未被调用过。

我甚至不需要应用程序来关心单元测试的麦克风,如果有一种方法从一开始就不显示对话框的话。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-07-23 05:46:29

在执行测试之前使用外壳命令xcrun simctl privacy (例如,在xcodebuild ...之前或作为目标设置中的准备步骤)

这是它的信息

代码语言:javascript
运行
复制
Grant, revoke, or reset privacy and permissions
Usage: simctl privacy <device> <action> <service> [<bundle identifier>]

    action
         The action to take:
             grant - Grant access without prompting. Requires bundle identifier.
             revoke - Revoke access, denying all use of the service. Requires bundle identifier.
             reset - Reset access, prompting on next use. Bundle identifier optional.
         Some permission changes will terminate the application if running.
    service
         The service:
             all - Apply the action to all services.
             calendar - Allow access to calendar.
             contacts-limited - Allow access to basic contact info.
             contacts - Allow access to full contact details.
             location - Allow access to location services when app is in use.
             location-always - Allow access to location services at all times.
             photos-add - Allow adding photos to the photo library.
             photos - Allow full access to the photo library.
             media-library - Allow access to the media library.
             microphone - Allow access to audio input.
             motion - Allow access to motion and fitness data.
             reminders - Allow access to reminders.
             siri - Allow use of the app with Siri.
    bundle identifier
         The bundle identifier of the target application.

Examples:
    reset all permissions: privacy <device> reset all
    grant test host photo permissions: privacy <device> grant photos com.example.app.test-host

Warning:
Normally applications must have valid Info.plist usage description keys and follow the API guidelines to request access to services. Using this command to bypass those requirements can mask bugs.
票数 1
EN

Stack Overflow用户

发布于 2020-07-25 17:11:54

中断监视器需要返回一个布尔值-其想法是,当检测到中断时,测试运行器将执行已添加到中断处理程序堆栈的所有中断处理程序,直到其中一个处理程序返回true。

https://developer.apple.com/documentation/xctest/xctestcase/handling_ui_interruptions

https://developer.apple.com/videos/play/wwdc2020/10220/

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

https://stackoverflow.com/questions/63041196

复制
相关文章

相似问题

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