如何使用selenium和appium通过自动化代码自动打开和关闭wifi。
答案 0 :(得分:0)
我还没试过,但发现一个代码如下: -
import io.appium.java_client.NetworkConnectionSetting;
NetworkConnectionSetting connection_wifi_off = new NetworkConnectionSetting(false, false, false);
NetworkConnectionSetting connection_wifi_on = new NetworkConnectionSetting(false, true, false);
来源: -
https://discuss.appium.io/t/how-to-turn-on-of-data-wifi-in-android-device-using-appium/11474
https://discuss.appium.io/t/why-appium-server-restart-adb-server-often/15479/4
OR
AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), dc);
// turn on all (data and wi-fi)
driver.setConnection(Connection.ALL);
assertEquals(Connection.ALL, driver.getConnection());
// turn off all (data and wi-fi)
driver.setConnection(Connection.NONE);
assertEquals(Connection.NONE, driver.getConnection());
// turn on airplane
driver.setConnection(Connection.AIRPLANE);
assertEquals(Connection.AIRPLANE, driver.getConnection());
// turn on data
driver.setConnection(Connection.DATA);
assertEquals(Connection.DATA, driver.getConnection());
// tunr on wi-fi
driver.setConnection(Connection.WIFI);
assertEquals(Connection.WIFI, driver.getConnection());
来源: -
https://medium.com/@eliasnogueira/how-to-deal-with-network-connection-in-appium-4-0-0-2134021fac25
希望它会对你有所帮助:)。
答案 1 :(得分:0)
启动活动,获取按钮并单击。
appPackage = "com.android.settings"
appActivity = '.wifi.WifiSettings'
driver.start_activity(appPackage, appActivity)
(driver.find_element_by_id('com.android.settings:id/switch_bar')).click()