How can I perform swipe left "with particular coordinate or height of screen" in XCUI test?

78 Views Asked by At
app.swipeLeft()

I'm using this swipeLeft function but it swipes at the middle of the page but I want to perform a swipe gesture at the top of the page. Is there any way I can give a coordinate or like a page top as a parameter while performing the swipe left function?

1

There are 1 best solutions below

0
Xaiv On

You could create a custom func and use app.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0)) to specify the top-left corner as the starting point. example...

func swipeLeft() { let app = XCUIApplication()

    // Set coordinates for the top-left 
    let startCoordinate = app.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.1))

    let endCoordinate = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1))


    startCoordinate.press(forDuration: 0.1, thenDragTo: endCoordinate)

   
}