Подвид пользовательского UIView не отображается в тестах пользовательского интерфейса

У меня есть пользовательский UIView, который имеет UITableView в качестве подпредставления. Я установил accessibilityLabel и accessibilityIdentifier как для UIView, так и для UITableView. Однако я могу запрашивать только UIView в своих UITests, а табличное представление вообще не отображается. Я также установил isAccessibilityElement на true.

  public lazy var tableView: UITableView = {
    let tableView = UITableView()
    tableView.dataSource = self
    tableView.delegate = self
    tableView.translatesAutoresizingMaskIntoConstraints = false
    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    return tableView
  }()

  // MARK: - Initialization

  override init(frame: CGRect) {
    super.init(frame: .zero)
    commonInit()
    self.layer.borderColor = UIColor.lightGray.cgColor
    self.layer.borderWidth = 1
  }

  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    commonInit()
  }

  // MARK: - Private Methods

  private func commonInit() {
    isAccessibilityElement = true
    accessibilityLabel = "Filter View"

    tableView.isAccessibilityElement = true
    tableView.accessibilityLabel = "Filter View Table"
    tableView.accessibilityIdentifier = "Filter View Table"

    addSubview(tableView)
    addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[tableView]-0-|", options: .alignAllLeft, metrics: nil, views: [ "tableView": tableView ]))
    addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[tableView]-0-|", options: .alignAllLeft, metrics: nil, views: [ "tableView": tableView ]))
  }

Я получаю доступ к элементам управления в своих UITests, например:

let filterView = app.otherElements["Filter View"] // Custom View
XCTAssertTrue(filterView.exists)
let filterTableView = filterView.otherElements["Filter View Table"] // Table View as Custom View's subview
XCTAssertTrue(filterTableView.exists)

person SleepNot    schedule 24.05.2019    source источник
comment
Я не знаю, как инициализируется ваш tableView. Ваш tableView инициализирован до того, как вы получите к нему доступ через идентификатор?   -  person Let's_Create    schedule 24.05.2019


Ответы (1)


Вы пытались использовать filterView.tables вместо filterView.otherElements ?

let filterTableView = filterView.tables["Filter View Table"] // Table View as Custom View's subview

person cesarmarch    schedule 24.05.2019
comment
Вы пытались найти свое представление таблицы, добавив точку останова и проверив отладчиком? - person cesarmarch; 28.05.2019