Xcode UItesting允许系统警报系列

我有问题,如果我尝试允许系列系统警报,工作只有一次,下一个警报不“允许”我googling更多的时间,并了解该职位:( Xcode 7 UItesting:如何解雇一系列系统警报代码 )没有..不工作。 在这里,我目前的代码,首先警报“允许”成功,未检测到下一个警报。

XCUIApplication *app = [[XCUIApplication alloc] init]; app.launchEnvironment = @{ @"isUITest" : @YES, @"withFakeData" : fakeData }; [app launch]; for (int i = 1; i <= self.possibleSystemAlerts; i++) { NSLog(@"%d", i); XCTestExpectation *expectation = [self expectationWithDescription:@"High Expectations"]; id monitor = [self addUIInterruptionMonitorWithDescription:@"Push notifications" handler:^BOOL(XCUIElement *_Nonnull interruptingElement) { XCUIElement *element = interruptingElement; XCUIElement *allow = element.buttons[@"Allow"]; XCUIElement *ok = element.buttons[@"OK"]; if ([ok exists]) { [ok tap]; [expectation fulfill]; return YES; } if ([allow exists]) { [allow forceTap]; [expectation fulfill]; return YES; } return NO; }]; [app tap]; [self waitForExpectationsWithTimeout:6.0 handler:^(NSError *error) { if (error) { NSLog(@"Timeout Error: %@", error); } }]; [self removeUIInterruptionMonitor:monitor]; } 

最好的问候,伊万。

UPD:

好吧,我find了解决办法,如何在第一次警报后,尝试closures秒(感谢这个网站: http : //www.it1me.com/it-answers?id= 32148965&s=Template:Viper&ttl=Xcode+7+UI+Testing% 3A +如何+解除+ +系列+ +系统+警报+在+代码 )只需要返回总是没有。

但是另外一个问题

  t = 10.18s Find: Descendants matching type Alert t = 10.18s Find: Identity Binding t = 11.19s Find the "Allow “MyApp” to access your location while you use the app?" Alert (retry 1) t = 11.19s Snapshot accessibility hierarchy for com.apple.springboard t = 11.26s Find: Descendants matching type Alert t = 11.26s Find: Identity Binding t = 12.27s Find the "Allow “MyApp” to access your location while you use the app?" Alert (retry 2) t = 12.27s Snapshot accessibility hierarchy for com.apple.springboard t = 12.33s Find: Descendants matching type Alert t = 12.34s Find: Identity Binding t = 12.42s Assertion Failure: UI Testing Failure - No matches found for "Allow “MyApp” to access your location while you use the app?" Alert Query input was {( Alert 0x7febe8731630: traits: 72057602627862528, {{25.0, 193.0}, {270.0, 182.0}}, label: '“MyApp” Would Like to Send You Notifications' )} 

他尝试closures第三次通知,而不是第二次,当然,他没有发现这个系统警报…

在应用程序启动之前,逐个创build警报处理程序。 另外,请确保在与警报交互之前tap()应用程序中的任何位置。 这是Xcode中的一个已知错误。

 addUIInterruptionMonitor(withDescription:"First Dialog") { (alert) -> Bool in alert.buttons["Allow"].tap() return true } addUIInterruptionMonitor(withDescription:"Second Dialog") { (alert) -> Bool in alert.buttons["Allow"].tap() return true } addUIInterruptionMonitor(withDescription:"Third Dialog") { (alert) -> Bool in alert.buttons["Allow"].tap() return true } let app = XCUIApplication() app.launch() app.tap() app.tap() app.tap() 

这三个水龙头将连续冷却每个警报处理程序,而不会在您的应用程序中实际触发任何事件。 另请注意,每个中断处理程序不会指定有关警报的任何信息,只有确认button。

使用For循环遍历可能的系统警报数似乎是代码中最可能的失败情况。 把它变成一个while循环来评估一个系统警报的存在,因为这个条件在视觉上会更清晰,涉及更less的总逻辑,并且不存在self.possibleSystemAlerts不正确的值的失败情况。

您的整个显示器逻辑也可以被删除。 testing将等待,直到应用程序闲置,届时您将有警报或没有警报。 评估其存在或缺乏,与之互动或结束循环。