Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
2.6k views
by The go-to Tester (360 points)
edited by
How to automate network of devices like switch off or on data.

1 Answer

0 like 0 dislike
by Master (1.2k points)

Turning the wi-fi or mobile data on or off is very simple.

See below code.

AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), dc);

// turn on all (data and wi-fi)
driver.setConnection(Connection.ALL);
assertEquals(Connection.ALL, driver.getConnection());
		
// turn off all (data and wi-fi)
driver.setConnection(Connection.NONE);
assertEquals(Connection.NONE, driver.getConnection());
		
// turn on airplane
driver.setConnection(Connection.AIRPLANE);
assertEquals(Connection.AIRPLANE, driver.getConnection());
		
// turn on data
driver.setConnection(Connection.DATA);
assertEquals(Connection.DATA, driver.getConnection());
		
// tunr on wi-fi
driver.setConnection(Connection.WIFI);		
assertEquals(Connection.WIFI, driver.getConnection());

In Appium API old versions <4.0.0 (for Java) the way to deal with network connection was:

AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), dc);

// init wi-fi and data enabled and airplane mode disabled

NetworkConnectionSetting ncs = new NetworkConnectionSetting(false, true, true);

driver.setNetworkConnection(ncs);

// turn off wi-fi

ncs.setWifi(false);

driver.setNetworkConnection(ncs);

// turn off data

ncs.setData(false);

driver.setNetworkConnection(ncs);

// turn on airplane mde

ncs.setAirplaneMode(true);

driver.setNetworkConnection(ncs);

// turn off airplane mode

ncs.setAirplaneMode(true);

driver.setNetworkConnection(ncs);

// turn on data

ncs.setData(true);

driver.setNetworkConnection(ncs);

// turn on wi-fi

ncs.setWifi(true);

driver.setNetworkConnection(ncs);


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...