Using Xcode UI test, I can not query the cells in a UITableView
The UITableView contains 3 cells :
import UIKit
@objc class DumpTable: UITableViewController {
var objects: [NSDate] = [NSDate]()
override func viewDidLoad() {
super.viewDidLoad()
objects.append(NSDate())
objects.append(NSDate())
objects.append(NSDate())
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Thetable"
tableView.accessibilityIdentifier = "Thetable"
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objects.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let object = objects[indexPath.row]
cell.textLabel!.text = object.description
cell.isAccessibilityElement = true
cell.accessibilityLabel = "Thecell"
cell.accessibilityIdentifier = "Thecell"
return cell
}
}
The test is really simple.
Given a UITableView with 3 cells, I'm trying to assert there are any cells available :
XCTAssertTrue(XCUIApplication().tables["Thetable"].exists)
XCTAssertTrue(XCUIApplication().tables["Thetable"].cells.count > 0)
It will then fail on the 2 assertions :
Assertion Failure: XCTAssertTrue failed -
/Users/damiengavard/Desktop/Table/TableUITests/TableUITests.swift:33: error: -[TableUITests.TableUITests testExample] : XCTAssertTrue failed -
https://github.com/dagio/TableCellAccessibility
Simply execute Cmd+U
I found the answer here. In order to make the UITableViewCell
accessible, the containing UITableView
cannot be accessible itself.
So, you just need to remove these lines:
tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Thetable"
tableView.accessibilityIdentifier = "Thetable"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With