iOS UI测试点击表的第一个索引



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

XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tables.staticTexts[@"Apr 04 16:28"] tap];

如果我的所有数据都是恒定的,那就太好了。但这些文本将不时更改。如何修改这些代码,使其始终位于表的第一个索引?

在应用程序的cells上使用-elementBoundByIndex

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

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

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

let app = XCUIApplication()
app.tables["table's accessibilityIdentifier"].cells.allElementsBoundByIndex.first?.tap()

"表的accessibilityIdentifier"应替换为表的accessibiliityIdentifier

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

相关内容

最新更新