简体   繁体   English

如何在测试脚本运行时以编程方式禁用(关闭)appium - AndroidDriver 中的 android 设备 wifi?

[英]How to disable(turn off) android device wifi in appium - AndroidDriver programmatically while test scripts is running?

我想在我的测试脚本中使用 appium - AndroidDriver 以编程方式关闭任何 android 设备中的 wifi 以检查网络拔出场景......

For Appium API version 4.0.0 and greater use the following:对于 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());

The methods in previous answers have been deprecated.先前答案中的方法已被弃用。 Please use these methods to manipulate WiFi connection:请使用这些方法来操作 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM