iOS UI测试轻触表的第一个索引

iOS UI测试轻触表的第一个索引,ios,xcode-ui-testing,Ios,Xcode Ui Testing,我刚开始学习iOS的UI测试。当我按下record并点击表的第一个索引时,它会生成如下代码 XCUIApplication *app = [[XCUIApplication alloc] init]; [app.tables.staticTexts[@"Apr 04 16:28"] tap]; 如果我所有的数据都是常量,那就好了。但这些文本将不时发生变化。如何修改这些代码,使其始终点击表的第一个索引 在应用程序的单元格上使用 XCUIApplication *app = [[XCUIAppli

我刚开始学习iOS的UI测试。当我按下record并点击表的第一个索引时,它会生成如下代码

XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tables.staticTexts[@"Apr 04 16:28"] tap];
如果我所有的数据都是常量,那就好了。但这些文本将不时发生变化。如何修改这些代码,使其始终点击表的第一个索引

在应用程序的
单元格上使用

XCUIApplication *app = [[XCUIApplication alloc] init];
[[app.cells elementBoundByIndex: 0] tap];

Swift 4

的解决方案对我不起作用。所以我用了:

let app = XCUIApplication()
app.tables["table's accessibilityIdentifier"].cells.allElementsBoundByIndex.first?.tap()
“表的accessibilityIdentifier”应替换为表的accessibilityIdentifier

这可能会为某人节省几分钟。

Swift

如果您正在进行UI测试,这将非常有用:

let cellCount = app.tables.cells.count
XCTAssertTrue(cellCount > 0)

let firstCell = app.tables.cells.element(boundBy: 0)
XCTAssertTrue(firstCell.exists)
firstCell.tap()
但要回答您的问题,您只需要以下两行:

let firstCell = app.tables.cells.element(boundBy: 0)
firstCell.tap()

好极了。做空并击中目标。感谢:)在Swift 4中,使用了“app.tables.cells.element(boundBy:0).tap()”而不是“[[app.cells elementBoundByIndex:0]tap];”