Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

pixeldock commented Oct 15, 2018

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
You can’t perform that action at this time.