我已经用EarlGrey做了几个月的UI测试,我开始用XCUITest做一些实验。我遇到了一个经典的问题,就是无法拒绝系统警报,这是很奇怪的,因为谷歌似乎实现了一个名为grey_systemAlertViewShown()的系统警报匹配器。我正在尝试使用GREYCondition检测系统警报。以下是我尝试过的:
- (void)waitForAndDismissSystemAlertForSeconds:(NSInteger)seconds {
GREYCondition *interactableCondition = [GREYCondition conditionWithName:@"isInteractable" block:^BOOL{
// Fails if element is not interactable
NSError *error;
[[EarlGrey selectElementWithMatcher:grey_systemAlertViewShown()] assertWithMatcher:grey_interactable() error:&error];
if (error) {
return NO;
} else {
NSError *allowButtonError;
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Allow")] assertWithMatcher:grey_notNil() error:&allowButtonError];
if (!allowButtonError) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Allow")] performAction:grey_tap()];
}
return YES;
}];
[interactableCondition waitWithTimeout:seconds];
}我也尝试过使用addUIInterruptionMonitorWithDescription,如这里所描述的(但是使用EarlGrey代码来做我在中断监视器中所做的事情):Xcode 7用户界面测试:如何在代码中排除一系列系统警报
两种方法都不起作用。在我的GREYCondition中,断点不会触发无错误情况,中断监视器也不会忽略我的警告。
有人知道EarlGrey是否支持取消系统警报吗?
发布于 2016-02-24 00:58:06
作为grey_systemAlertViewShown 指示的文档,grey_systemAlertViewShown只是检查是否显示了系统警报视图。API的一个更好的用法是断言没有显示系统警报(可能是因为测试应用程序模拟了导致系统警报的代码)。
Code that taps a button that requests causes system alert to be shown (for ex: requests user's geo location) comes here...
// Assert that in the test app system alert view is not shown because we have mocked out the part of code that requests user location.
[[EarlGrey selectElementWithMatcher:grey_anything()] assertWithMatcher:grey_not(grey_systemAlertViewShown())];在编写这篇文章时,EarlGrey不能排除系统警报视图。该应用程序启动的Alertview可以被取消。常见问题有一个问题,表明如果存在模态对话框,EarlGrey测试将失败。
发布于 2017-02-13 20:12:59
我们找到的解决这个问题的最好方法是包括一个用于测试的启动参数,在这个参数中,我们不会注册应用程序进行通知。
类似于:
if [[[NSProcessInfo processInfo] arguments] containsObject:argument] { return; }
在你打电话之前
[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications];
这样,“您要允许推送通知吗.”警报不会出现。
发布于 2019-09-04 10:52:41
可以使用AppleSimulatorUtils util授予所有所需的权限。
这种方法不需要取消警报并节省时间。
通过在终端应用程序中输入下一步命令来安装util
brew tap wix/brew
brew install applesimutils
并给予许可
applesimutils --byId <simulator UDID> --bundle <bundle identifier> --setPermissions "notifications=YES"
有关更多信息和示例,请参见
https://stackoverflow.com/questions/35589615
复制相似问题