【问题标题】:Q: UITests - How to get collectionCell element inside collectionView nested with TableView cell?问:UITests - 如何在 collectionView 中获取与 TableView 单元格嵌套的 collectionCell 元素?
【发布时间】:2017-11-03 04:28:49
【问题描述】:

我是 UITests 的初学者。目前,我有一个问题,我无法访问 collectionViewCell 中的元素。

我的 UI 元素结构:

UIViewController

  • UITableView

-- UITableViewCell

   ---> UICollectionView
    ----> UICollectionViewCell
      -----> The element that I would like to get.

我试过下面的代码:

let tableCellContainer = app.tables["HomeRVMPTableView"].cells.element(boundBy: 0) // Get the first Cell of TableView
let collectionContainer = tableCellContainer.collectionViews["ContainerItemCollectionView"].cells.element(boundBy: 1) // Get the second Cell inside collectionView
let collectionElement = collectionContainer.staticTexts["BuyCashCard"]
XCTAssertFalse(!collectionElement.exists)  // FAILED

有什么方法可以更轻松地访问 collectionViewCell/tableViewCell 吗?开始使用 UITests 时我很累。

【问题讨论】:

  • 如果您正在检查 exists 是否为 false 并且它失败了,那么看起来您 正在 获取单元格。所以基本上细胞确实存在......
  • @Oletha 很抱歉我的错误,我已经更新了上面的代码 (XCTAssertFalse(!collectionElement.exists))。在这种情况下它仍然不起作用

标签: ios uicollectionview xctest


【解决方案1】:

感谢大家的帮助,我刚刚找到了另一种访问 tableview 中的集合视图的方法。

这是我的代码:

let tableCellContainer = app.tables["MainTableView"].cells.element(boundBy: 1) 
let cell = tableCellContainer.staticTexts["Brazil"]
cell.tap()            
 XCTAssert(cell.exists)

希望这能帮助另一个和我有同样问题的人。

【讨论】:

    【解决方案2】:

    要使该行失败,collectionElement 必须实际存在。用XCTAssert(collectionElement.exists)替换你的失败行

    XCTAssertFalse 在条件为真时失败。 XCTAssert(相当于XCTAssertTrue)在条件为真时成功。

    【讨论】:

    • 我已经更新了上面的代码,XCTAssert(collectionElement.exists) 仍然不起作用。
    猜你喜欢
    • 2020-04-03
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多