相关疑难解决方法(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
查看次数

标签 统计

xcode ×2

xcode-ui-testing ×2

ios ×1

ios9 ×1

swift ×1

xcode7-beta4 ×1

xctest ×1