相关疑难解决方法(0)

Xcode7 | Xcode UI测试| 如何处理位置服务警报?

我正在使用Xcode7/iOS 9中引入的XCUIApplication,XCUIElement和XCUIElementQuery为我的应用程序编写UI测试用例.

我遇到了路障.测试用例中的一个屏幕需要iOS的位置服务.正如预期的那样,系统会提示用户允许使用名为" Allow “App name” to access your location while you use the app?with Allow&Don't Allowbuttons"的警报来使用位置服务.

问题是或许似乎由于警报由OS本身呈现,因此它不存在于Application的元素子树中.

我记录了以下内容:

print("XYZ:\(app.alerts.count)")//0
var existence = app.staticTexts["Allow “App Name” to access your location while you use the app?"].exists
print("XYZ:\(existence)")//false
existence  = app.buttons["Allow"].exists
print("XYZ:\(existence)") //false
Run Code Online (Sandbox Code Playgroud)

甚至UI录制生成类似的代码:

XCUIApplication().alerts["Allow “App Name” to access your location while you use the app?"].collectionViews.buttons["Allow"].tap()
Run Code Online (Sandbox Code Playgroud)

我还没有找到任何可以让我解决这个问题的API.例如:

  • 点按屏幕上的某个位置
  • 在应用外部获取提醒

那我该怎么办呢?有没有办法配置测试目标,以便不需要位置服务授权.

xcode xctest ios9 xcode-ui-testing xcode7-beta4

31
推荐指数
2
解决办法
1万
查看次数

Xcode 7 UI测试:解除推送和位置警报

我遇到了Xcode 7 UI测试的问题.

我的用户登录后,应用程序会显示两个警报,即请求位置警报和推送通知警报.这些通知一个接一个地显示.位置一出现在第一位.

我尝试自动解雇它们以开始我的测试.

为此,我添加了两个UIInterruptionMonitor,第一个用于Location Alert,第二个用于Notification Push Alert.

    addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
        /* Dismiss Location Dialog */
        if alert.collectionViews.buttons["Allow"].exists {
            alert.collectionViews.buttons["Allow"].tap()
            return true
        }
        return false
    }
    addUIInterruptionMonitorWithDescription("Push Dialog") { (alert) -> Bool in
        /* Dismiss Push Dialog */
        if alert.collectionViews.buttons["OK"].exists {
            alert.collectionViews.buttons["OK"].tap()
            return true
        }
        return false
    }
Run Code Online (Sandbox Code Playgroud)

但只触发Location 1,从不调用Push Notifications UIInterruptionMonitor的处理程序.

如果我在返回true 请求位置 UIInterruptionMonitor因为这等后接受的答案指定.两个处理程序都被调用,但两个UIInterruptionMonitor中alert参数都链接到请求位置警报视图,因此永远找不到"确定"按钮.

如何解除这两个连续的警报视图?

xcode ios swift xcode-ui-testing

31
推荐指数
2
解决办法
5589
查看次数

是否可以使用EarlGrey(iOS UI测试)解除系统警报?

我开始尝试使用EarlGrey一点点,现在已经使用XCUITest进行了UI测试.我遇到了无法解除系统警报的经典问题,这很奇怪,因为看起来Google实现了一个名为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];
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用这里描述的addUIInterruptionMonitorWithDescription(但是使用EarlGrey代码来完成我在上面的中断监视器中所做的事情):Xcode 7 UI测试:如何在代码中解除一系列系统警报

两种方法都不奏效.我的GREYCondition中的非错误情况不会触发断点,并且中断监视器也不会解除我的警报.

有人知道EarlGrey是否支持解雇系统警报?

ui-testing ios earlgrey

4
推荐指数
1
解决办法
1385
查看次数

Xcode UI Testing允许系统警报系列

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

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]; …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ui-testing ios xcode-ui-testing

4
推荐指数
1
解决办法
3252
查看次数

有没有办法强制机器人在xcode持续集成中的ui测试下始终接受权限警报?

我需要使用大量的模拟器在xcode服务器上运行持续集成.有没有办法强制它始终接受权限警报,如:

允许"App"访问您的照片

等等...

xcode continuous-integration xcode-ui-testing

2
推荐指数
1
解决办法
552
查看次数

Swift 错误“变量在其自身的初始值内使用”

我正在为我的应用程序编写 XCUITest。我声明警报是为了waitForExpectationsWithTimeout使我的测试异步......但是它在第 5 行Variable used within its own initial value的声明中抛出错误alert

    let timeout = NSTimeInterval()
    let app = XCUIApplication()

    let exists = NSPredicate(format: "exists == 1")
    let alert = alert.buttons["OK"]


    testCase.addUIInterruptionMonitorWithDescription("Enable Notifications") { (alert) -> Bool in
            alert.buttons["OK"].tap()
        return true
    }

    self.buttons["Enable notifications"].tap()
    testCase.expectationForPredicate(exists, evaluatedWithObject: alert, handler: nil)
    testCase.waitForExpectationsWithTimeout(timeout, handler: nil)
    app.tap()
Run Code Online (Sandbox Code Playgroud)

有人能告诉我为什么它会抛出这个错误以及我能做些什么来解决这个问题。提前致谢。

xcode ios swift xcode-ui-testing

1
推荐指数
1
解决办法
5608
查看次数