簡體   English   中英

自定義UIView的子視圖未出現在UI測試中

[英]Subview of a custom UIView not appearing in UI Tests

我有一個自定義UIView ,它有一個UITableView作為子視圖。 我為UIViewUITableView設置了accessibilityLabel和accessibilityIdentifier。 但是,我只能在我的UITests上查詢UIView ,並且表格視圖根本不顯示。 我還將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)

您是否嘗試過使用filterView.tables而不是filterView.otherElements

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM