Reputation: 31
I'm trying to delete an element doing swipe left over it. This option exist in two ways in my application.
The second option I could not reproduce it with XCUIElements function.
The only function I found to do is element.swipeLeft() but did not found how to do a long swipe left.
Upvotes: 3
Views: 1310
Reputation: 7649
You can use press(forDuration:thenDragTo:)
to execute a drag from one side of the cell to the other.
let app = XCUIApplication()
let cell = app.cells.element(boundBy: 0) // first cell on the page
let rightOffset = CGVector(dx: 0.95, dy: 0.5)
let leftOffset = CGVector(dx: 0.05, dy: 0.5)
let cellFarRightCoordinate = cell.coordinate(withNormalizedOffset: rightOffset)
let cellFarLeftCoordinate = cell.coordinate(withNormalizedOffset: leftOffset)
// drag from right to left to delete
cellFarRightCoordinate.press(forDuration: 0.1, thenDragTo: cellFarLeftCoordinate)
Note that when creating coordinates from an element, you give a CGVector
which is normalized to the size of the element (where 1.0
is the full width/height of the element), but if you create a coordinate from a coordinate, you must give a CGVector
with absolute values.
Upvotes: 4