当我的应用程序第一次启动时,它会显示一个对话框,要求用户在允许应用程序使用麦克风时单击“不允许”或“确定”进行响应。
问题是,当第一次启动单元测试时,会出现相同的对话框,它会停止测试的执行。如果单元测试是由Xcode Server运行的,则无法手动干预并单击按钮。
有没有一种方法可以自动关闭这个对话框?单击哪个按钮进行单元测试并不重要。
我尝试将以下代码放入XCTestCase setUp()
方法中:
[self addUIInterruptionMonitorWithDescription:@"Interruption Monitor" handler:^{BOOL(XCUIElement * element) {
XCUIElement *button = [[element buttons] elementAtIndex:0];
if (button) {
[button tap];
}
}];
但是处理程序从未被调用过。
我甚至不需要应用程序来关心单元测试的麦克风,如果有一种方法从一开始就不显示对话框的话。
发布于 2020-07-23 05:46:29
在执行测试之前使用外壳命令xcrun simctl privacy
(例如,在xcodebuild ...
之前或作为目标设置中的准备步骤)
这是它的信息
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.
发布于 2020-07-25 17:11:54
中断监视器需要返回一个布尔值-其想法是,当检测到中断时,测试运行器将执行已添加到中断处理程序堆栈的所有中断处理程序,直到其中一个处理程序返回true。
https://developer.apple.com/documentation/xctest/xctestcase/handling_ui_interruptions
https://stackoverflow.com/questions/63041196
复制相似问题