Created
October 15, 2018 12:43
-
-
Save pixeldock/40a668074a8c91c7bab05a675efc3a52 to your computer and use it in GitHub Desktop.
Helper methods to open ControlCenter and NotificationCenter from Xcode UITests
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 | |
extension XCTestCase { | |
var springboard: XCUIApplication { | |
return XCUIApplication(bundleIdentifier: "com.apple.springboard") | |
} | |
func closeApp() { | |
XCUIDevice.shared.press(XCUIDevice.Button.home) | |
} | |
func openNotificationCenter(from app: XCUIApplication) { | |
let coord1 = app.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.01)) | |
let coord2 = app.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.8)) | |
coord1.press(forDuration: 0.1, thenDragTo: coord2) | |
} | |
func openControlCenter(from app: XCUIApplication) { | |
let coord1 = app.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.01)) | |
let coord2 = app.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.2)) | |
coord1.press(forDuration: 0.1, thenDragTo: coord2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inside your UITest functions you can now for example do the following:
To open ControlCenter from your app you can now simply call:
To close your app and open NotificationCenter from the Springboard you can call: