如何在UI Test Xcode 7.2中查询自定义视图的标签

时间:2016-02-26 12:15:28

标签: ios swift xcode-ui-testing ui-testing

我有自定义视图和标签作为子视图。我已经为LocationViewIf,locationLb提供了辅助功能标识符。

这是代码

  func testSpecificLocationSelection() {
        let app = XCUIApplication()

        let expectedLocationLable =  app.collectionViews/*@START_MENU_TOKEN@*/.cells.staticTexts["100 feet road Indiranagar"]/*[[".cells.staticTexts[\"100 feet road Indiranagar\"]",".staticTexts[\"100 feet road Indiranagar\"]"],[[[-1,1],[-1,0]]],[1]]@END_MENU_TOKEN@*/
        let exists = NSPredicate(format: "exists == true")
        expectationForPredicate(exists, evaluatedWithObject: expectedLocationLable, handler: nil)

        waitForExpectationsWithTimeout(10, handler: nil)

        XCTAssert(expectedLocationLable.exists)

        app.collectionViews/*@START_MENU_TOKEN@*/.cells.staticTexts["100 feet road Indiranagar"]/*[[".cells.staticTexts[\"100 feet road Indiranagar\"]",".staticTexts[\"100 feet road Indiranagar\"]"],[[[-1,1],[-1,0]]],[1]]@END_MENU_TOKEN@*/.tap()



        let actualLocation =  app.otherElements["LocationViewIf"].childrenMatchingType(.StaticText)

        let lll = actualLocation.staticTexts["locationLb"]

        print(lll.debugDescription)

        XCTAssert(lll.label == expectedLocationLable.label)

    }

当我跑步时,我正在获得UITesting失败 - 找不到StaticText的匹配

调试说明:

  Other 0x7ae38ce0: traits: 8589934592, {{0.0, 0.0}, {320.0, 480.0}}
  Other 0x7ae38700: traits: 8589934592, {{0.0, 0.0}, {320.0, 480.0}}
  Other 0x7ee5e140: traits: 8589934592, {{0.0, 0.0}, {320.0, 480.0}}
  Other 0x7ee5dbd0: traits: 8589934592, {{0.0, 0.0}, {320.0, 480.0}}
  Other 0x7ee741f0: traits: 8589934592
  Other 0x7ae3dce0: traits: 8589934592, {{0.0, 0.0}, {320.0, 480.0}}
  Other 0x7ae3d730: {{0.0, 0.0}, {320.0, 480.0}}
  Other 0x7ee753a0: traits: 8589934592
  Other 0x7ee74da0: traits: 8589934592, {{0.0, 0.0}, {320.0, 480.0}}
  Other 0x7ee764b0: {{0.0, 0.0}, {320.0, 20.0}}
  Other 0x7ee77020: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
  Other 0x7ee775f0: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
  Other 0x7ee77be0: traits: 8389120, {{137.0, 0.0}, {50.0, 20.0}}, label: '5:39 PM'
  Other 0x7ee781c0: traits: 8388608, {{274.0, 0.0}, {10.0, 20.0}}, identifier: 'GeofenceLocationTrackingOn', label: 'Region tracking on'
  Other 0x7ee787d0: traits: 8388608, {{290.0, 0.0}, {25.0, 20.0}}, label: '-100% battery power'
  Other 0x7ee76a60: {{0.0, 0.0}, {320.0, 20.0}}
}
↪︎Find: Elements matching predicate '"LocationViewIf" IN identifiers'
  Output: {
    Other 0x7ee735e0: traits: 8589934592, {{0.0, 430.0}, {320.0, 50.0}}, identifier: 'LocationViewIf'
  }
  ↪︎Find: Children matching type StaticText
    ↪︎Find: Descendants matching type StaticText
      ↪︎Find: Elements matching predicate '"locationLb" IN identifiers'

0 个答案:

没有答案