我有问题,如果我尝试允许系列系统警报,只工作一次,而下一个警报不“允许”
我在谷歌上搜索了更多时间,并且知道了那个帖子:(Xcode 7 UI 测试:如何在代码中消除一系列系统警报 https://stackoverflow.com/questions/32148965/xcode-7-ui-testing-how-to-dismiss-a-series-of-system-alerts-in-code)
没什么..不工作。
这是我当前的代码,第一个警报成功“允许”,未检测到下一个警报。
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:
好的,我找到了解决方案,如何在第一次警报后尝试关闭第二次(感谢这个网站:)只需要始终返回“否”。
但另一个问题...
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'
)}
他尝试关闭第三个通知,而不是第二个,当然他没有发现这个系统警报......
在应用程序启动之前,一一创建警报处理程序。另外,请确保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()
这三个点击将连续触发每个警报处理程序,而不会实际触发应用程序中的任何事件。另请注意,每个中断处理程序都没有指定anything关于警报,只有确认按钮。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)