How to turn on or off Wi Fi using Appium?

How to turn on or off wifi or data connection using appium?
If any one know it please share code.

Hi @chetan_thummar,

Try this:

adb -s shell “svc wifi enable”

Note: This can be used only for Android

Through command line? i want it to add in my test case.

http://appium.io/docs/en/commands/device/network/toggle-wifi/

Try this out.

1 Like

@Prajith_KP : tried also, not working.

im using appium v 1.13.0
Device v 9

Then execute the above mentioned adb command using a process.
https://www.tutorialspoint.com/java/lang/runtime_exec.htm

Thanks for sharing. i will try this solution.

https://appium.io/docs/en/writing-running-appium/other/network-connection/

try this one @chetan_thummar
// this one for set the connection
((AndroidDriver)driver).setConnection(new ConnectionState(ConnectionState.DATA_MASK));

// and this one for checkk the connection
ConnectionState con = ((AndroidDriver)driver).getConnection();
System.out.println(con.isDataEnabled());
System.out.println(con.isWiFiEnabled());