Last active
July 1, 2024 22:46
-
-
Save squeaky-nose/92e38e0af8770b4c79c5052995c9a484 to your computer and use it in GitHub Desktop.
XCUITest disable keyboard swipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
final class AppUITests: XCTestCase { | |
override func setUpWithError() throws { | |
SpringboardHelper.showKeyboardIfNeeded() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
class SpringboardHelper { | |
private static var keyboardDismissed = false | |
/// Call this from the setUp() function of any UI test that deals with the keyboard. | |
static func showKeyboardIfNeeded() { | |
if !keyboardDismissed { | |
let springBoard = XCUIApplication(bundleIdentifier: "com.apple.springboard") | |
springBoard.activate() | |
springBoard.windows.firstMatch.swipeDown(velocity: .slow) | |
springBoard.windows.firstMatch.tap() | |
springBoard.windows.firstMatch.swipeUp(velocity: .slow) | |
keyboardDismissed = true | |
} | |
} | |
} |
The single tap would trigger a tap somewhere on the center of the screen/device. Ideally just abit above the keyboard.
I believe that i added it because If you dont 'tap' after the swipe down - it doesnt dismiss the search results. Manually trying it now myself in the simulator - it doesn't seem to be doing that.
Thanks for reply! I got it that there might be search results. If I find any issues, I'll let you know 🙏
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This solution has worked very well for me, but I have one question. The line 12, what does the single
tap()
do? At least, it has worked for me withouttap()
.