I am trying to enable air plane mode just after closing the application (driver.closeapp()), but getting an exeception. Please let me know if anything need to be taken care of to avoid the exception.
Below is the exception:
org.openqa.selenium.WebDriverException: ERROR running Appium command: Cannot read property ‘restart’ of null
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at io.appium.java_client.android.AndroidDriver.setNetworkConnection(AndroidDriver.java:129)
If it is not necessary to close app you can try putting current running app activity in background [Press Home Button ] and then enable air plane mode.
// Press Home Key
_driver.sendKeyEvent(AndroidKeyCode.HOME);
You could quit the session after closing app ( driver.quit() ) and open a new session which would open , say, phone settings, enable Air plane mode, quit the session, and open a new one with your app and do whatever you plan to do while in Air plane mode.