iOS UI 测试点击 table 的第一个索引
iOS UI Testing tap on first index of the table
我刚开始在 iOS 学习 UI 测试。当我按下记录并点击 table 的第一个索引时,它会生成这样的代码。
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tables.staticTexts[@"Apr 04 16:28"] tap];
如果我的所有数据都是恒定的就好了。但这些文本会不时更改。我如何修改这些代码,使其始终点击 table 的第一个索引?
在您应用的 cells
上使用 -elementBoundByIndex
。
XCUIApplication *app = [[XCUIApplication alloc] init];
[[app.cells elementBoundByIndex: 0] tap];
Swift 4
@Joe Masilotti 的解决方案对我不起作用。所以我用了:
let app = XCUIApplication()
app.tables["table's accessibilityIdentifier"].cells.allElementsBoundByIndex.first?.tap()
"table's accessibilityIdentifier" 应替换为您的 table 的 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()
我刚开始在 iOS 学习 UI 测试。当我按下记录并点击 table 的第一个索引时,它会生成这样的代码。
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.tables.staticTexts[@"Apr 04 16:28"] tap];
如果我的所有数据都是恒定的就好了。但这些文本会不时更改。我如何修改这些代码,使其始终点击 table 的第一个索引?
在您应用的 cells
上使用 -elementBoundByIndex
。
XCUIApplication *app = [[XCUIApplication alloc] init];
[[app.cells elementBoundByIndex: 0] tap];
Swift 4
@Joe Masilotti 的解决方案对我不起作用。所以我用了:
let app = XCUIApplication()
app.tables["table's accessibilityIdentifier"].cells.allElementsBoundByIndex.first?.tap()
"table's accessibilityIdentifier" 应替换为您的 table 的 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()