[英]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.