Dismiss view with swipe on iOS 13 XCUITest
Asked Answered
M

3

5

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.

Masters answered 24/12, 2019 at 3:33 Comment(0)
A
11

I have just started playing with UI Testing and found that if you add a velocity swiping away an action sheet works.

.swipeDown(velocity: XCUIGestureVelocity.fast)

https://developer.apple.com/documentation/xctest/xcuigesturevelocity

Amerce answered 9/10, 2020 at 15:3 Comment(4)
Is this new? I may have missed this before if not..Masters
I am not sure, it says it has been around since Xcode 12.0+, I have only looked for it recently.Amerce
@NicolasYuste have tried tweaking it using one of the initialisers?Amerce
Working on local but not on CI, strange.Worthen
C
16

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.

Catchpole answered 28/12, 2019 at 9:56 Comment(0)
A
11

I have just started playing with UI Testing and found that if you add a velocity swiping away an action sheet works.

.swipeDown(velocity: XCUIGestureVelocity.fast)

https://developer.apple.com/documentation/xctest/xcuigesturevelocity

Amerce answered 9/10, 2020 at 15:3 Comment(4)
Is this new? I may have missed this before if not..Masters
I am not sure, it says it has been around since Xcode 12.0+, I have only looked for it recently.Amerce
@NicolasYuste have tried tweaking it using one of the initialisers?Amerce
Working on local but not on CI, strange.Worthen
G
0

this worked for me

let navigationBar = app.navigationBars["Add to Journal"]
navigationBar.swipeDown()
Gensmer answered 3/6, 2023 at 0:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.