Reputation: 63
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
Upvotes: 6
Views: 2036
Reputation: 7649
In your example project, you are looking for a table within a table.
let tableView = XCUIApplication().tables.containingType(.Table, identifier: "Thetable")
You should use matchingIdentifier:
, which searches through the tables on the screen, instead of containingType:identifier:
, which searches through the descendants of the tables on the screen.
Upvotes: 0
Reputation: 325
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"
Upvotes: 4