UI 测试从 uitableviewcell 获取文本
UI testing get text from uitableviewcell
我正在编写一些 UI 测试,目前我在匹配 tableview 单元格中的某些文本时遇到问题。
所以我想测试 tableview 是否具有它需要的所有情况。
我试过如下:
if !app.staticTexts["sometext"].exists {
// FAIL
}
但这行不通,因为它找不到文本,然后我发现了类似这样的内容:
app.tables.cells.staticTexts["some text"].exists
最后但同样重要的是:
app.tables.cells.containingType(.StaticText, identifier: "some text")
但似乎永远找不到文本,它在屏幕上。
有人知道如何从表格视图单元格中获取文本吗?
在您的两个 UITableView 上设置 accessibilityIdentifier,这样您就可以每次都选择正确的table。
app.tables["myIdentifier"].cells.staticTexts["some text"]
如果正确定义了单元格的标识符 - 一切就绪。尝试 -
let app = XCUIApplication()
let tablesQuery = app.tables
XCTAssertTrue(tablesQuery.cells.containing(.staticText, identifier: "my identifier").staticTexts["Some Text"].exists,
"Failure: Something went wrong.")
我正在编写一些 UI 测试,目前我在匹配 tableview 单元格中的某些文本时遇到问题。
所以我想测试 tableview 是否具有它需要的所有情况。
我试过如下:
if !app.staticTexts["sometext"].exists {
// FAIL
}
但这行不通,因为它找不到文本,然后我发现了类似这样的内容:
app.tables.cells.staticTexts["some text"].exists
最后但同样重要的是:
app.tables.cells.containingType(.StaticText, identifier: "some text")
但似乎永远找不到文本,它在屏幕上。 有人知道如何从表格视图单元格中获取文本吗?
在您的两个 UITableView 上设置 accessibilityIdentifier,这样您就可以每次都选择正确的table。
app.tables["myIdentifier"].cells.staticTexts["some text"]
如果正确定义了单元格的标识符 - 一切就绪。尝试 -
let app = XCUIApplication()
let tablesQuery = app.tables
XCTAssertTrue(tablesQuery.cells.containing(.staticText, identifier: "my identifier").staticTexts["Some Text"].exists,
"Failure: Something went wrong.")