Skip to content

Instantly share code, notes, and snippets.

@sushant-here
Last active July 1, 2024 22:46
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
}
}
}
@woin2ee
Copy link

woin2ee commented Jun 10, 2024

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 without tap().

@sushant-here
Copy link
Author

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.

@woin2ee
Copy link

woin2ee commented Jun 11, 2024

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