【问题标题】:UI testing get text from uitableviewcellUI 测试从 uitableviewcell 获取文本
【发布时间】:2016-12-28 20:21:46
【问题描述】:

我正在编写一些 UI 测试,但目前在匹配 tableview 单元格中的某些文本时遇到问题。

所以我想测试一个 tableview 是否具有它需要的所有情况。

我试过如下:

if !app.staticTexts["sometext"].exists {
// FAIL
}

但这不起作用,因为它没有找到文本,然后我发现了这样的东西:

app.tables.cells.staticTexts["some text"].exists

最后但并非最不重要的是:

app.tables.cells.containingType(.StaticText, identifier: "some text")

但似乎永远找不到文本并且它在屏幕上。 有人知道如何从 tableview 单元格中获取文本吗?

【问题讨论】:

  • 我发现了问题。我有 2 个 tableview 和 app.tables 正在使用第一个 tableview 而不是第二个。所以我只需要以某种方式切换到第二个表格视图。

标签: ios uitableview xctest xcode-ui-testing


【解决方案1】:

在你的两个 UITableViews 上设置accessibilityIdentifier,那么你每次都可以选择正确的表。

app.tables["myIdentifier"].cells.staticTexts["some text"]

【讨论】:

  • 你知道如何用 KIF 框架做同样的事情吗??
  • 抱歉,我不熟悉 KIF API。
【解决方案2】:

当单元格的标识符定义明确时 - 事情就会到位。试一试——

    let app = XCUIApplication()
    let tablesQuery = app.tables
    XCTAssertTrue(tablesQuery.cells.containing(.staticText, identifier: "my identifier").staticTexts["Some Text"].exists,
                  "Failure: Something went wrong.")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    相关资源
    最近更新 更多