Programmatically sending an app to background

前端 未结 4 1805

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 applic

4条回答
  •  心在旅途
    2020-12-10 05:02

    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)
    }
    

提交回复
热议问题