Xcode UITest推送通知警报无法点击“允许”

时间:2017-02-12 16:27:34

标签: ios xcode xcode-ui-testing

是否有类似的情况?因此,应用程序打开,推送通知警报显示询问用户是否允许接收推送通知,测试单击“不允许”,即使我有以下代码:

func testClickSystemAlert(){
        let app = XCUIApplication();
        XCUIApplication().alerts["“纳豆行” Would Like to Send You Notifications"].buttons["Allow"].tap()
    }

这里是print的输出(XCUIApplication()。debugDescription);

Attributes: Application 0x60000016c540: {{0.0, 0.0}, {414.0, 736.0}}, label: '纳豆行'
Element subtree:
 →Application 0x60000016c540: {{0.0, 0.0}, {414.0, 736.0}}, label: '纳豆行'
    Window 0x60000016bc40: Main Window, {{0.0, 0.0}, {414.0, 736.0}}
      Other 0x60000016c780: {{0.0, 0.0}, {414.0, 736.0}}
        Other 0x60000016c9c0: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
          ScrollView 0x60000016bf40: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
            Image 0x60000016c0c0: traits: 8589934596, {{0.0, 0.0}, {414.0, 736.0}}, identifier: '1'
          PageIndicator 0x600000163000: traits: 8589939200, {{132.0, 691.0}, {150.0, 55.0}}, value: page 1 of 4
    Window 0x6000001693c0: {{0.0, 0.0}, {414.0, 736.0}}
      StatusBar 0x600000169240: {{0.0, 0.0}, {414.0, 20.0}}
        Other 0x60000016ca80: {{0.0, 0.0}, {414.0, 20.0}}
        Other 0x60000016cb40: {{0.0, 0.0}, {414.0, 20.0}}
          Other 0x60000016cc00: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
          Other 0x60000016ccc0: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
          Other 0x60000016cd80: traits: 8389120, {{181.0, 0.0}, {56.0, 20.0}}, label: '12:29 AM'
          Other 0x60000016ce40: traits: 8388608, {{384.0, 0.0}, {25.0, 20.0}}, label: '-100% battery power'
Path to element:
 →Application 0x60000016c540: {{0.0, 0.0}, {414.0, 736.0}}, label: '纳豆行'
Query chain:
 →Find: Target Application 0x6000000b7340
  Output: {
    Application 0x60000016c540: {{0.0, 0.0}, {414.0, 736.0}}, label: '纳豆行'
  }

3 个答案:

答案 0 :(得分:6)

我最终使用了这个:

addUIInterruptionMonitor(withDescription: "Allow push") { (alerts) -> Bool in
            if(alerts.buttons["Allow"].exists){
                alerts.buttons["Allow"].tap();
            }
            return true;
        }

它会点击允许按钮

答案 1 :(得分:1)

我建议使用JPSimulatorHacks在单元测试中自动授予权限。但这不适用于设备,仅适用于模拟器。

答案 2 :(得分:1)

原始答案仅在添加应用程序点击

时有效
addUIInterruptionMonitor(withDescription: "YOUR TITLE") { (alert) -> Bool in
                if alert.buttons["OK"].exists {
                    alert.buttons["OK"].tap()
                }
                return true
            }
XCUIApplication().tap() // which is very important!!!