Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UI Testing tap on first index of the table

I just started studying for UI testing in iOS. When I press record and tap on first index of the table, it generate codes like this.

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

It is good if all my data are constant. But those text will be changed from time to time. How can I modify these code so that it will always tap on the first index of the table?

like image 776
Khant Thu Linn Avatar asked Apr 12 '16 07:04

Khant Thu Linn


2 Answers

Use -elementBoundByIndex on your app's cells.

XCUIApplication *app = [[XCUIApplication alloc] init];
[[app.cells elementBoundByIndex: 0] tap];
like image 64
Joe Masilotti Avatar answered Oct 18 '22 07:10

Joe Masilotti


Swift

If you're doing UI Testing, this will be helpful:

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

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

To answer your question though, you only need these 2 lines:

let firstCell = app.tables.cells.element(boundBy: 0)
firstCell.tap()
like image 30
kakubei Avatar answered Oct 18 '22 08:10

kakubei