Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can wifi be switched on/off in test case through robotium

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.

like image 669
Ryhot Avatar asked Dec 03 '12 10:12

Ryhot


People also ask

What is Robotium used for?

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.

What to unit test?

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.


1 Answers

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

like image 61
Onivas Avatar answered Nov 16 '22 03:11

Onivas