I've been writing UITests, and after recording a test to open a modal view, and swipe the modal down to the bottom of the screen to dismiss it, I get some code like this (as there is a table view in there):
var tablesQuery = app.tables.element(boundBy: 0)
tablesQuery.swipeDown()
The problem is, this doesn't always work. Sometimes (especially on iPad), the view moves down a bit and jumps back into place (rather than dismissing) when playing the test back.
Apple must have had the same issue and put in a better solution to dismiss modal views (.present) on iOS 13 XCUITests.
Is there a way to reliably dismiss these suckers that is supported by the core test framework so I don't have to do any custom fiddling with gestures or whatnot?
Thanks for any help!
If there aren't any obvious solutions, I guess a hacked heavy duty down gesture might answer this question as well... As all answers out there are for very tiny or slight versions of the swipes, not full screen dismissal gestures. But I'd like your context on a supported solution first (do you know a supported solution doesn't exist - for example?)
Thanks for any help! - supported/maintained by Apple way of dismissing views via XCTest framework, or info about this not existing will answer this question.
The synthetic swipeDown()
gesture is not very reliable, or just not held till far enough to produce the modal dismissal in every case.
What you can do is create a customized swipe down gesture like follows:
var tablesQuery = app.tables.element(boundBy: 0)
let start = tablesQuery.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0))
let finish = tablesQuery.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 3.0))
start.press(forDuration: 0.5, thenDragTo: finish)
You can play with the dy
offset value as needed for a longer swipe on screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With