以编程方式将应用发送到后台 [英] Programmatically sending an app to background
本文介绍了以编程方式将应用发送到后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将应用程序发送到后台?与如何调用XCUIApplication.terminate()
相似,我有一些UI元素可以在applicationDidBecomeActive(_:)
上进行测试.有人知道这是否完全可能吗?
Is there a way to send the application to background? Similarly to how you can call XCUIApplication.terminate()
, I have some UI Elements to test on applicationDidBecomeActive(_:)
. Does anyone know if this is at all possible?
推荐答案
我建议签出XCUIDevice
.这是您可以按主页"按钮然后重新启动应用程序的方式
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)
}
这篇关于以编程方式将应用发送到后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文