1

Anybody has a working example how to manipulate with flight mode in Appium for Android? Appim docu is for this topic for some reason not complete, none of proposed ways works, together with "this should work....". I am stuck with flight mode.

Cœur
  • 37,241
  • 25
  • 195
  • 267
junior
  • 45
  • 1
  • 11
  • This question has been answered here. [Answer:-how to automate the airplane mode in appium automation](https://stackoverflow.com/a/62050475/10553774) – Prajeeth Anand May 27 '20 at 18:41

5 Answers5

1

As per appium documentation you can toggle airplane mode as mentioned below.

driver.toggleAirplaneMode();
Muzzamil
  • 2,823
  • 2
  • 11
  • 23
1

In Latest Android version permission disabled for enabled and disable Airplane mode, but you can achieve using below commands In Appium Latest Java client you can do it using

To disable Wifi and Data in Android:

driver.setConnection(new ConnectionStateBuilder().withWiFiDisabled().withDataDisabled().build());

To enabled WiFI and Data in Android: driver.setConnection(new ConnectionStateBuilder().withWiFiEnabled().withDataEnabled().build());

Suraj
  • 317
  • 4
  • 7
0

I'm actually not familiar with Appium, but you didn't mention if you've looked for solutions outside the appium.io documentation. I'm guessing driver.toggleAirplaneMode() hasn't worked for you?

In that case, have you tried converting the Python code in this answer from 2016?

# To enable/disable flight mode
def enableFlightMode(self,context):
        driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE)
        driver.implicitly_wait(10)
        if driver.network_connection == 1:
            self.report_pass("The network connection is disabled in the mobile and flight mode is active.")
        else:
            self.report_fail("The flight mode is not active yet!")
SoyChai
  • 320
  • 2
  • 11
0

Appium documentation has a pretty solid introduction on how to change Connection type.

Java API is here and here

driver.getConnection() will return you current state and then you can change it to needed one.

Note: Changing Airplane Mode state on real devices only works for Android 6 and older

dmle
  • 3,498
  • 1
  • 14
  • 22
0

Appium documention is uncomplete on many issues, my both working methods for dealing with flight mode an and wifi are here:

    @SuppressWarnings("rawtypes")
public void pressFlightMode(int waitingTime){
    if (isIOS()) {
        //should be implemented
    } else {
    try {
            ((AndroidDriver)driver).toggleAirplaneMode();
            sleep(waitingTime);
        } catch (Exception e ) {
            System.out.println("Error turning on flight mode.");
     }
    }
}

@SuppressWarnings("rawtypes")
public void pressWifi(int waitingTime){
    if (isIOS()) {
        //to be implemented     
        } else {
            try {
                ((AndroidDriver)driver).toggleWifi();            
                sleep(waitingTime);
            } catch (Exception e ) {
                System.out.println("Error turning off flight mode.");
            }
        }
}
junior
  • 45
  • 1
  • 11