[英]How to disable(turn off) android device wifi in appium - AndroidDriver programmatically while test scripts is running?
我想在我的测试脚本中使用 appium - AndroidDriver 以编程方式关闭任何 android 设备中的 wifi 以检查网络拔出场景......
对于 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());
先前答案中的方法已被弃用。 请使用这些方法来操作 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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.