我想在appcript中以编程方式关闭任何Android设备中的wifi,使用appium - AndroidDriver检查网络拔插方案...
答案 0 :(得分:0)
对于Appium API 4.0.0及更高版本,请使用以下命令:
AndroidDriver driver;
//turn off all connections
driver.setConnection(Connection.NONE);
assertEquals(Connection.All, driver.getConnection());
//Turn on data and Wifi
driver.setConnection(Connection.ALL);
assertEquals(Connection.All, driver.getConnection());
//Turn just Wifi on
driver.setConnection(Connection.WIFI);
assertEquals(Connection.WIFI, driver.getConnection());
答案 1 :(得分:0)
先前答案中的方法已被弃用。请使用以下方法来操纵WiFi连接:
public void WifiOn() {
ConnectionState state = driver.setConnection(new ConnectionStateBuilder().withWiFiEnabled().build());
Assert.assertTrue(state.isWiFiEnabled(), "Wifi is not switched on");
logger.LogTestInfo("WiFi turned on");
}
public void WifiOff() {
ConnectionState state = driver.setConnection(new ConnectionStateBuilder().withWiFiDisabled().build());
Assert.assertFalse(state.isWiFiEnabled(), "Wifi is not switched off");
logger.LogTestInfo("WiFi turned off");
}