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?
Background refers to the data used when the app is doing some activity in the background, which is not active right now. This is due to the fact that whether they are active or not, apps consume data. They may be. checking for updates or refreshing the user content.
1: You have to invoke the service's startForeground() method within 5 seconds after starting the service. To do this, you can call startForeground() in onCreate() method of service. public class AppService extends Service { .... @Override public void onCreate() { startForeground(9999, Notification()) } .... }
You can use Process. killProcess(int pid) to kill processes that have the same UID with your App. You can use ActivityManager. killBackgroundProcesses(String packageName),with KILL_BACKGROUND_PROCESSES permission in your manifest(for API >= 8) or ActivityManager.
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With