Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismiss view with swipe on iOS 13 XCUITest

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.

like image 540
TheJeff Avatar asked Dec 13 '22 09:12

TheJeff


1 Answers

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.

like image 83
atineoSE Avatar answered Jan 11 '23 00:01

atineoSE