可WIFI开/关测试的情况下,通过robotium切换 [英] can wifi be switched on/off in test case through robotium
问题描述
我们可以打开/关闭了Wi-Fi设备在robotium一个测试用例? 因为我是测试,需要WiFi能够在最初的阶段,然后关闭了Wi-Fi,并继续测试的问题。
是的,你可以做到这一点,看看这个例子:
公共无效testNoNetworkConnection()抛出异常{
setWifiEnabled(假); //做的东西solo.something setWifiEnabled(真正的); } 私人无效setWifiEnabled(布尔州){ WifiManager wifiManager =(WifiManager)solo.getCurrentActivity()getSystemService(Context.WIFI_SERVICE)。 wifiManager.setWifiEnabled(州); }
记住要添加的权限在你的清单文件:
<使用-权限的Android:名称=android.permission.ACCESS_WIFI_STATE/>
<使用-权限的Android:名称=android.permission.CHANGE_WIFI_STATE/>
编辑:随着新Robotium 5.3.1您可以使用 setWiFiData(布尔turnedOn)以打开WiFi或关闭(见的文档)
享受
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.
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
这篇关于可WIFI开/关测试的情况下,通过robotium切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!