fede1608
fede1608

Reputation: 2878

Testing UICollectionView infinite scroll with XCUI Test case

How can I test infinite scroll in one of my collection views? I tried simulating the scroll like it's explained in this "pull to refresh" example but it didn't worked.

let app = XCUIApplication()
let start = app.coordinateWithNormalizedOffset(CGVectorMake(1, 6))
let finish = app.coordinateWithNormalizedOffset(CGVectorMake(1, 0))
var x = 0
while(x < 20){
  x++
  start.pressForDuration(0, thenDragToCoordinate: finish)
}

(The while condition is just for testing, I will change it to ask if a specific element exists when I get the scroll to work)

Upvotes: 2

Views: 2097

Answers (1)

Joe Masilotti
Joe Masilotti

Reputation: 17008

If you are only testing infinite scroll you probably don't need to drop down to the coordinate-level API. Instead, just swipe the collection view as if the user was scrolling.

let app = XCUIApplication()
let newCell = app.staticTexts["Page 2 Item"]
XCTAssertFalse(newCell.exists)

app.collectionView.element.swipeUp()
XCTAssert(newCell.exists)

Upvotes: 7

Related Questions