在我uiautomator测试,我想这样做如何检查uiautomator是否连接了wifi?
if(wifi is connected) {
doSth();
} else {
doSthElse();
}
我可以检查?
在我uiautomator测试,我想这样做如何检查uiautomator是否连接了wifi?
if(wifi is connected) {
doSth();
} else {
doSthElse();
}
我可以检查?
方法-1
转到无线上网的页面 - 勾选 “Conncted” 你的SSID下面的字符串。
方法-2
退房的adb shell netcfg
放和grep为WiFi接口有效ip地址,mostly- wlan0
。
方法-3(但它只是对根植电话)
退房看跌adb shell wpa_cli ifname=wlan0 status
,它提供了无线网络连接与否的信息。
以上所有方法都可以使用uiautomator进行编码。
由于版本21(?)UiAutomator可以访问Instrumentation,因此可以访问上下文。
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
Context context = instrumentation.getContext();
WifiManager wManager = context.getSystemService(Context.WIFI_SERVICE); //this works for other services as well
现在你可以使用所有WifiManager方法,如:
wManager.isWifiEnabled()
wManager.setWifiEnabled(boolean) //turn wifi on and off
这可以帮助你:http://stackoverflow.com/questions/10009804/check-network-connection-android – Sharj