I would recommend checking out XCUIDevice
. Here is how you might press the home button and then relaunch the application
func testExample() {
// Has a nav bar.
XCTAssert(XCUIApplication().navigationBars.element.exists)
XCUIDevice().press(XCUIDeviceButton.home)
// Before Swift 3: XCUIDevice().pressButton(XCUIDeviceButton.Home)
XCUIApplication().launch()
// Navigationbar still there on second launch.
XCTAssert(XCUIApplication().navigationBars.element.exists)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…