Getting exception in android while enabling Air plane mode after closing the app

Hi All,

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)

Build info: version: ‘2.46.0’, revision: ‘87c69e2’, time: ‘2015-06-04 16:17:10’
System info: host: ‘nag1-ldl-41649’, ip: ‘192.168.56.1’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_31’
Driver info: io.appium.java_client.android.AndroidDriver

Can you share your code ?

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

1 Like

Hi Amit,

There is specific requirement to close application first and then enable the air plane mode, this is why we need to automate in same manner.

Steps we are performing:

  1. Setting up the capabilities
  2. Using driver object we close the application - driver.closeapp()
  3. Now we enable air plane mode using below approach.

public void enableAirplaneMode(){
NetworkConnectionSetting connection = new NetworkConnectionSetting(true, false, false);
androidDriver().setNetworkConnection(connection);
}

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.

Appium needs to automate an application.

Alexis++

Appium expects to work with your application. When you call close, things go badly, quickly. See https://github.com/appium/appium/issues/4350

If you close the app without using the appium call, like we did, things work much better.