Skip to content

Instantly share code, notes, and snippets.

@pixeldock
Created October 15, 2018 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixeldock/40a668074a8c91c7bab05a675efc3a52 to your computer and use it in GitHub Desktop.
Save pixeldock/40a668074a8c91c7bab05a675efc3a52 to your computer and use it in GitHub Desktop.
Helper methods to open ControlCenter and NotificationCenter from Xcode UITests
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)
}
}
@pixeldock
Copy link
Author

Inside your UITest functions you can now for example do the following:

To open ControlCenter from your app you can now simply call:

openControlCenter(from: XCUIApplication())

To close your app and open NotificationCenter from the Springboard you can call:

closeApp()
openNotificationCenter(from: springboard)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment