如何在android上使用selenium或appium自动化Chrome浏览器?

前端之家收集整理的这篇文章主要介绍了如何在android上使用selenium或appium自动化Chrome浏览器?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在 Android设备上自动Android Chrome浏览器(不只是webview或其他浏览器,而是Chrome浏览器).我认为这可以通过这个链接 https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started—android,但它自动化我的PC浏览器浏览器.

我也试过Appium,但日志后没有任何反应:

debug: executing: adb install C:\Users\hidden\Downloads\AppiumForWindows-0.14.2\
Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk

当我尝试从浏览器访问信息时,我得到了这个:

info: Responding to client with error: {"status":13,"value":{"message":"An unkno
wn server-side error occurred while processing the command.","origValue":"Did no
t successfully proxy server command"},"sessionId":"666c9e4f-7653-487a-b299-959d4
000ca79"}

我的环境变量PATH中有chromedriver.exe,整个日志如下所示:

info: Welcome to Appium v0.14.2
info: Appium REST http interface listener started on 127.0.0.1:5555
   info  - socket.io started
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"platform":"ANDROID
","app":"chrome","browserName":"android","browserConnectionEnabled":true,"app-pa
ckage":"com.android.chrome","device":"android","rotatable":true,"app-activity":"
com.google.android.apps.chrome.Main","takesScreenshot":true,"version":""}}
info: Looks like we want chrome on android
info: Creating new appium session 666c9e4f-7653-487a-b299-959d4000ca79
info: Ensuring Chromedriver exists
debug: Pushing unlock helper app to device...
debug: executing: adb install C:\Users\hidden\Downloads\AppiumForWindows-0.14.2\
Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk
warn:  killed=false,code=1,signal=null
debug: Appium request initiated at /wd/hub/status
debug: Request received with params: {}
debug: Proxying command to 127.0.0.1:9515
info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/status
","method":"GET"}
info: Responding to client with error: {"status":13,"sessionId":"666c9e4f-7653-487a-b299-959d4
000ca79"}
GET /wd/hub/status 500 1014ms - 238b
POST /wd/hub/session 200 31311ms

谢谢.

解决方法

debug: executing: adb install C:\Users\hidden\Downloads\AppiumForWindows-0.14.2\
Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk

如果此处没有发生任何事情,那么您必须再次重新启动ARM仿真器和appium服务器/ chromedriver.我多次遇到这种情况,并注意到很多次adb关闭并失去连接.如果我重新启动abd,一切都会开始工作.这只是一个安装apk的adb命令,它应该花费时间取决于apk的大小但不多.

public static void main(String[] args) throws MalformedURLException{
    DesiredCapabilities  capabilities = new DesiredCapabilities();
    capabilities.setCapability("device","Android");
    capabilities.setCapability("app","Chrome");
    capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
    capabilities.setCapability(CapabilityType.VERSION,"4.3");
    capabilities.setCapability(CapabilityType.PLATFORM,"WINDOWS");
    WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
    driver.get("http://www.yahoo.com");
}

我有这段代码在appium自动化android chrome浏览器上运行良好.在上面的日志中,您的chromedriver尚未成功启动,因此浏览器未自动化.我有appium日志,它自动化chrome浏览器:

此外,ChromeDriver和Chrome APK的每个组合都无法正常工作.我几天以来一直在努力,发现:
Chrome驱动程序2.3和Chrome APK 29.xxx兼容.
Chrome驱动程序2.9 / 2.8和Chrome APK 30.xx或31.xx无效.

关于Just ChromeDriver:
如果您没有设置功能,您提到的铬链接自动化PC浏览器.像这样的东西:

DesiredCapabilities capabilities=new DesiredCapabilities();//DesiredCapabilities.chrome();
    ChromeOptions options=new ChromeOptions();
    options.setExperimentalOptions("androidPackage","com.android.chrome");
    capabilities.setCapability(ChromeOptions.CAPABILITY,options);

你必须设置这个功能,因为你只是使用chromedriver(而不是appium).我正在努力,但找不到能力.此外,您必须自己在命令promt上启动ChromDriver,它将在9515端口监听任何自动化.

猜你在找的Android相关文章