Android Robotium : Make Wi-Fi and Mobile Data Network Enable & Disable Programatically
|While working with android application development or automating test scripts for android application testing sometimes we need to ON/OFF Wi-Fi and Mobile Data Access feature explicitly.
Android library facilitates to do that in the following way:
For Wi-Fi:
WifiManager wifiman=(WifiManager)solo.getCurrentActivity().getSystemService(Context.WIFI_SERVICE);
wifiman.setWifiEnabled(false);
Passing false will disable Wi-Fi and true enables it.
For Mobile Data:
ConnectivityManager dataManager=(ConnectivityManager)solo.getCurrentActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
Method dataMtd = ConnectivityManager.class.getDeclaredMethod(“setMobileDataEnabled”, boolean.class);
dataMtd.setAccessible(true);
dataMtd.invoke(dataManager, true);
Please Note:
The following permission must be configured in AndroidManifest.xml file .
For Wi-Fi:
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE
For Mobile Data:
android.permission.CHANGE_NETWORK_STATE
- Bring the auto Sync magic of Protractor to Selenium with Java - October 23, 2015
- Restarting Appium Server could improve various server freezing issues and may improve execution time - January 20, 2015
- Appium with iOS 8 and XCode 6 : What’s new? - November 5, 2014
- REST API automation testing using Apache HttpClient – The Approach - October 3, 2014
- An Overview of mobile application : Moving forward to automation - October 1, 2014
- An introduction to REST - September 29, 2014
- Run ChromeDriver with Chrome Driver Service to reduce script execution time significantly - September 26, 2014
- Selenium WebDriver – Get Cookies from an existing session and add those to a newly instantiated WebDriver browser instance. - September 26, 2014
- Simulate Copy Paste action using Java Robot and Clipboard class - September 26, 2014
- Android : How to test if Android Application has memory leaks - August 11, 2014
-
David F
-
http://mindfiremobiletesting.wordpress.com Mindfire Mobile Testing