Xcode Uc Test: Request an Access Request on a UITableViewCell

Problem

Using Xcode UI test, I cannot request cells in a UITableView

Explanation

UITableView

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
    }
}

Test

The test is really simple.

Given a UITableView with 3 cells, I'm trying to claim that any cells are available:

XCTAssertTrue(XCUIApplication().tables["Thetable"].exists)
XCTAssertTrue(XCUIApplication().tables["Thetable"].cells.count > 0)

Then he will abandon two statements:

Assertion Failure: XCTAssertTrue failed - 
/Users/damiengavard/Desktop/Table/TableUITests/TableUITests.swift:33: error: -[TableUITests.TableUITests testExample] : XCTAssertTrue failed - 

How to play

https://github.com/dagio/TableCellAccessibility

Just do Cmd + U

+4
source share
2 answers

I found the answer here . To make accessible UITableViewCell, the containing UITableViewmay not be available to itself.

So you just need to remove these lines:

tableView.isAccessibilityElement = true
tableView.accessibilityLabel = "Thetable"
tableView.accessibilityIdentifier = "Thetable"
+2

.

let tableView = XCUIApplication().tables.containingType(.Table, identifier: "Thetable")

matchingIdentifier:, containingType:identifier:, .

0

Source: https://habr.com/ru/post/1653673/


All Articles