Q: UITests - How to get collectionCell element inside collectionView nested with TableView cell?

Viewed 1152

I'm the beginner of UITests. Currently, I have an issue that I can not access element inside collectionViewCell.

My UI elements structure:

UIViewController

  • UITableView

-- UITableViewCell

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

I've tried with the code below:

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

Is there any way to access collectionViewCell/tableViewCell easier? I'm so tired when start working UITests with that.

2 Answers

Thank you guys for helping me, I just found another way to access the collection view inside the tableview.

Here is my code:

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

Hope this will help another guy who has the same issue like me.

For that line to fail, the collectionElement must actually exist. Replace your failing line with XCTAssert(collectionElement.exists)

XCTAssertFalse fails when the condition is true. XCTAssert (equivalent to XCTAssertTrue) succeeds when the condition is true.

Related