can we switch on/off the wi-fi of the device in a test cases in robotium? because i am testing an issue which needs wifi to be on in initial phase then turning off the wi-fi and continue with testing.
Robotium is an open-source test framework for writing automatic gray box testing cases for Android applications. With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities.
Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. This testing methodology is done during the development process by the software developers and sometimes QA staff.
Yes you can do it, see the example:
public void testNoNetworkConnection() throws Exception {
setWifiEnabled(false); // do stuff solo.something setWifiEnabled(true); } private void setWifiEnabled(boolean state) { WifiManager wifiManager = (WifiManager)solo.getCurrentActivity().getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(state); }
Remember to add permission in your Manifest file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
EDIT: With the new Robotium 5.3.1 you can use setWiFiData(Boolean turnedOn) to turn wifi on or off (See documentation)
Enjoy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With