【问题标题】:How can I verify existence of text inside a table view row given its index in an XCTest UI Test?给定 XCTest UI 测试中的索引,如何验证表格视图行中是否存在文本?
【发布时间】:2015-11-28 16:19:36
【问题描述】:

我正在使用 XCTest UI 测试框架来检查表格视图中的行。在我的测试中,我需要在给定索引的情况下验证表格视图行中是否存在文本。

我正在考虑使用tableRows.elementBoundByIndex 方法,但它没有返回任何内容。调用tableRows.count 返回的行数为零。该表存在并已填充,因为我可以成功查询行内的文本:

XCTAssertEqual(app.tables.staticTexts["Cute Alpaca"].exists)

如何在 XCTest UI 测试中根据其索引验证一行中是否存在文本?

【问题讨论】:

    标签: xcode swift xctest xcode-ui-testing


    【解决方案1】:

    对于你的情况,我认为这段代码会对你有所帮助。

    let tableCellContainer = app.tables["HomeTableView"].cells.element(boundBy: 1) // Get the first Cell
    let cell = tableCellContainer.staticTexts["Brazil"]
    XCTAssert(cell.exists)
    

    问候,

    【讨论】:

      【解决方案2】:

      事实证明tableRows 实际上并没有检测到UITableView 中的行。请改用cells

      我感觉 tableRowstableColumns 用于在 Mac OS X 上进行测试,而在 iOS 上我们有 UITableViewCellUICollectionViewCell。或者这可能是一个错误,因为我们仍处于测试阶段。

      let table = app.tables.element
      XCTAssertTrue(table.exists)
      
      let cell = table.cells.elementBoundByIndex(2)
      XCTAssertTrue(cell.exists)
      let indexedText = cell.staticTexts.element
      XCTAssertTrue(indexedText.exists)
      

      或单排

      XCTAssertTrue(app.tables.element.cells.elementBoundByIndex(2).exists)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        • 2022-11-08
        相关资源
        最近更新 更多