gpt4 book ai didi

android - 如何通过 Appium 为 Android 设备获取/设置网络连接

转载 作者:太空狗 更新时间:2023-10-29 15:26:18 26 4
gpt4 key购买 nike

我尝试使用 Appium 来测试我的 android 设备:我需要做的基本工作是获取网络连接状态。环境:[Appium Server v 1.4.0 on Windows 7 + Python Client 0.16]

from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = 'SamSung Galaxy Note4'
desired_caps['browserName'] = 'Chrome'


driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.get('http://google.com')
print driver.contexts
print driver.network_connection
time.sleep(5)
driver.quit()

但是,当我运行脚本时,我得到了以下输出:

> [u'NATIVE_APP', u'WEBVIEW_1'] Traceback (most recent call last):  
> File "D:/PycharmProjects/Work/hello/Work_YM/Appium/sample_1.py", line
> 15, in <module>
> print driver.network_connection() File "C:\Python27\lib\site-packages\appium\webdriver\webdriver.py", line
> 601, in network_connection
> return self.execute(Command.GET_NETWORK_CONNECTION, {})['value'] File
> "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
> line 195, in execute
> self.error_handler.check_response(response) File "C:\Python27\lib\site-packages\appium\webdriver\errorhandler.py", line
> 29, in check_response
> raise wde selenium.common.exceptions.WebDriverException: Message: "unknown command:
> session/31fe15845b2580877c1900c31d8f688d/network_connection"

似乎 network_connection(它是 webDriver 的一个属性)不起作用,任何人都可以提供一些帮助吗?谢谢!

最佳答案

您可以通过 AndroidDriver 获取/更改网络连接设置。但是,它仅适用于低于 5 的 Android 版本。

AppiumDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("..."), caps);
NetworkConnectionSetting networkConnection = new NetworkConnectionSetting(false, true, false); // airplane mode, wiif, data

networkConnection.setData(true); // enable mobile data
networkConnection.setWifi(false); // close wifi

((AndroidDriver<WebElement>)driver).setNetworkConnection(networkConnection);
networkConnection = ((AndroidDriver<WebElement>)driver).getNetworkConnection();

关于android - 如何通过 Appium 为 Android 设备获取/设置网络连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31305213/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com