1

How can I switch ON/OFF AIRPLANE mode and wifi using Appium ?

Selenium has below option:

NetworkConnection mobileDriver = (NetworkConnection) driver;
 if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
   // enabling Airplane mode
   mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);
 }

But when I create AndroidDriver object and typecast it with above code, getting error that such typecast is not possible.

Any other way ?

  • We do it using a small custom app that appium runs, I don't know why it doesn't work. – Rsf Nov 15 '16 at 9:15
3

This helper method will help you to turn on the wifi while your test case is still running:

static AppiumDriver driver;    

public static void wifiOff() throws InterruptedException {
    NetworkConnection mobileDriver = (NetworkConnection) driver;
    if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
       // enabling Airplane mode
       mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);
    }
}

Works for me.

0

Try using hardware keys. Write the steps to turn it on and off by using hardware buttons.

  • this will only work until the next OS update and change of menu structure – Rsf Nov 15 '16 at 9:16
0

According to the Appium Java API docs you'd do something like this (I haven't tested it):

driver.setConnection(Connection.AIRPLANE);

Note that only the Android driver supports this (not the iOS driver). See Adjusting Network Connection.

0

Currently you can switch between ON/OFF options of Airplane mode only in Android. There is still no option to do that on iOS. This being said, this is what you would do to enable/disable airplane mode in Android.

((AndroidDriver) DRIVER).setConnection(Connection.AIRPLANE);
boolean connectionStatus = ((AndroidDriver) DRIVER)
    .getConnection()
    .equals(Connection.AIRPLANE);
if (connectionStatus) {
    //Then do something
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.