This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
6 / 6
Jul 2018

Am not able to turn on aero plane mode or turn off wifi using appium

I used below script:
NetworkConnection mobileDriver = (NetworkConnection) aDriver;
if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
// enabling Airplane mode
mobileDriver.setNetworkConnection(ConnectionType.AIRPLANE_MODE);

Exception:
744 - org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: ‘Command ‘C:\Users\TestUser\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ce11160bd2dwqeqa3 shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true’ exited with code 4294967295’; Stderr: 'Security exception: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=28306, uid=2000

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=28306, uid=2000
at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:23593)
at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:23442)
at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:24271)
at com.android.server.am.ActivityManagerShellCommand.runSendBroadcast(ActivityManagerShellCommand.java:642)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:155)
at android.os.ShellCommand.exec(ShellCommand.java:96)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:18871)
at android.os.Binder.shellCommand(Binder.java:581)
at android.os.Binder.onTransact(Binder.java:481)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4775)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3862)
at android.os.Binder.execTransact(Binder.java:682)’; Code: ‘4294967295’ (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7.85 seconds

  • created

    Jul '18
  • last reply

    Jul '18
  • 5

    replies

  • 996

    views

  • 4

    users

Hi, I’m using this custom methods to turn of and of the connection, I’m switching off the wifi, I don’t need Airplane.
Of course you can customize to turn on Airplane mode .withAirplaneModeEnabled().
required java client 6.0.0.

public void setConnectionToOFF() {
try {
driver.setConnection(new ConnectionStateBuilder().withWiFiDisabled().build());
System.out.println("Switching OFF the connection : " + driver.getConnection());
} catch (Exception e) {
System.out.println(“Connection could not be switch OFF”);
}
}

public void setConnectionToON() {
	try {
		driver.setConnection(new ConnectionStateBuilder().withWiFiEnabled().build());
		System.out.println("Switching On the connection: " + driver.getConnection());
	} catch (Exception e) {
		System.out.println("Connection could not be switch ON");
	}
}

unfortunately not, you’ll get connection refused. Although the driver manage to close the WIFI :))
I’m running the tests on 6.0 so there is working.
I might suggest to do it as well. but depends on your app.
When i’m trying to run the test on 8 or 7, there is a 80% change that the test will fail. mostly the driver cannot find some elements.