Xcode UI 测试允许系统警报系列 [英] Xcode UI Testing allow system alerts series

查看:26
本文介绍了Xcode UI 测试允许系统警报系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,如果我尝试允许系列系统警报,只工作一次,而下一个警报不允许"我在谷歌上搜索了更多时间,并了解了该帖子:(Xcode 7 UI 测试:如何在代码中解除一系列系统警报)没什么..不行.这是我当前的代码,第一个警报允许"成功,下一个警报未检测到..

I have problem, if i try allow series system alert, work only one time, and next alert not "allowing" I googling more time, and know about that post: (Xcode 7 UI Testing: how to dismiss a series of system alerts in code) Nothing.. not work. Here my current code, first alert "allowed" successfully, next alert not detected..

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];
}

最好的问候,伊万.

更新:

好的,我找到了解决方案,如何在第一次警报后尝试关闭第二次(感谢本网站:http://www.it1me.com/it-answers?id=32148965&s=Template:Viper&ttl=Xcode+7+UI+Testing%3A+how+to+dismiss+a+series+of+system+alerts+in+code) 只需要返回总是没有.

Okay, i found solution, how after first alert, try close second (thanks for this site: http://www.it1me.com/it-answers?id=32148965&s=Template:Viper&ttl=Xcode+7+UI+Testing%3A+how+to+dismiss+a+series+of+system+alerts+in+code) Just need return always NO.

还有一个问题...

    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'
)}

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

He try close third notification, not second, of course he not found this system alert...

推荐答案

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

Create the alert handlers one by one, before the app launches. Also, make sure to tap() anywhere on the app before interacting with the alert. This is a known bug in 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()

这三个点击将连续触发每个警报处理程序,而不会实际触发您应用中的任何事件.另请注意,每个中断处理程序都没有指定关于警报的任何内容,仅指定了确认按钮.

These three taps will fir each alert handler in succession without actually triggering any events in your app. Also note that each interruption handler doesn't specify anything about the alert, only the confirmation button.

这篇关于Xcode UI 测试允许系统警报系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆