有没有办法将应用程序发送到后台?与你如何打电话类似 XCUIApplication.terminate()
,我有一些要测试的UI元素 applicationDidBecomeActive(_:)
。有谁知道这是否可能?
有没有办法将应用程序发送到后台?与你如何打电话类似 XCUIApplication.terminate()
,我有一些要测试的UI元素 applicationDidBecomeActive(_:)
。有谁知道这是否可能?
我建议退房 XCUIDevice
。您可以按下主页按钮,然后重新启动应用程序
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)
}
我建议退房 XCUIDevice
。您可以按下主页按钮,然后重新启动应用程序
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)
}
我刚试过 UIApplication.sharedApplication().performSelector("suspend")
成功。
dispatch_after(2, dispatch_get_main_queue(), {
// suspend the app after two seconds
UIApplication.sharedApplication().performSelector("suspend")
})
在Xcode 9.0中,Apple推出了 XCUIApplication.activate()
。 activate()
将在必要时启动应用程序,但如果它已在运行,则不会终止它。从而:
func testExample() {
// Background the app
XCUIDevice().press(.home)
// Reactivate the app
XCUIApplication().launch()
}