I'm trying to write a UITest that involves tapping on a button within a UITableViewCell.
When I try to record my tap actions when tapping on the cell, XCode generates the line:
[[[[[XCUIApplication alloc] init].tables childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:1].otherElements[@"Problems"] tap];
When played back, this results in the same action as tapping on the cell itself, which is not what I want.
Is there a way I can make it specifically press on the button?
Set the accessibility identifier on the custom button. Then you can access it directly under test.
Application Code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.accessoryView = CustomButton()
cell.accessoryView.accessibilityIdentifier = "New Problem \(indexPath.row)"
}
Test Code:
let app = XCUIApplication()
app.buttons["New Problem 42"].tap()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.