Skip to content

Instantly share code, notes, and snippets.

@sushant-here
Last active February 20, 2024 02:52
Show Gist options
  • Save sushant-here/92e38e0af8770b4c79c5052995c9a484 to your computer and use it in GitHub Desktop.
Save sushant-here/92e38e0af8770b4c79c5052995c9a484 to your computer and use it in GitHub Desktop.
XCUITest disable keyboard swipe
import XCTest
final class AppUITests: XCTestCase {
override func setUpWithError() throws {
SpringboardHelper.showKeyboardIfNeeded()
}
}
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
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment