2017-02-12 97 views
3

任何人都有类似的情况?因此,应用程序开启,推送通知警报显示,询问用户允许接收推送通知,测试单击甚至不容许我有以下代码:Xcode UITest推送通知警报无法点击“允许”

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

这里是打印输出(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: '纳豆行' 
    } 

回答

1

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

4

我最终使用这样的:

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

会点击允许按钮