我怎样才能使用selenium或appium自动化Android上的浏览器?

我正在尝试在Android设备上自动化Android Chrome浏览器(不仅仅是一个Web浏览器或其他浏览器,而是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"} 

我的环境variablesPATH中有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,"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"} GET /wd/hub/status 500 1014ms - 238b POST /wd/hub/session 200 31311ms 

谢谢。

Solutions Collecting From Web of "我怎样才能使用selenium或appium自动化Android上的浏览器?"

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

如果这里没有任何事情发生,那么您必须重新启动ARM模拟器和appium服务器/ chromedriver。 我多次遇到这种情况,并注意到很多次adbclosures,失去连接。 如果我重新启动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"); } 

我有这段代码,它运行在自动化android chrome浏览器的appium上。 在上面的日志中,你的chromedriver没有启动成功,所以浏览器不是自动的。 我有自动铬浏览器的appium日志: 在这里输入图像说明 另外,ChromeDriver和Chrome的每个组合都不起作用。 我一直在努力挣扎,发现:Chrome驱动程序2.3和Chrome APK 29.xxx是兼容的。 Chrome驱动2.9 / 2.8和Chrome APK 30.xx或31.xx无法正常工作。

关于ChromeDriver:你提到的铬链接将自动化PC浏览器,如果你没有设置的能力。 像这样的东西:

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

你必须设置这个function,因为你只是使用chromedriver(而不是appium)。 我正在这个工作,但无法find能力。 另外你将不得不自己启动ChromDriver命令promt将在9515端口监听任何自动化。

1)阅读appium日志,看看是什么版本的铬驱动程序引用。 2)在线检查最新的chromedriver版本。 截至今天最新版本是2.23。 下载这个Windows并解压缩http://chromedriver.storage.googleapis.com/index.html?path=2.23/ 3)升级Appium(今天最新 – 1.4.16.1)现在转到这个位置,C:\ Program Files文件(x86 )\ appium \ node_modules \ appium \ node_modules \ appium-chromedriver \ chromedriver \赢

并粘贴chromedriver.exe这里(replace旧的)

4)

  public AndroidDriver<AndroidElement> startChrome() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName", "AndroidDevice"); capabilities.setCapability("newCommandTimeout", 180); capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main"); try { driver = new AndroidDriver<>(new URL(appiumURL), capabilities); driver.get("google.com") } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return driver; } 

5)如果这不起作用,请确保检查到appium日志,如果它指向更新的chrome版本

首先检查您的移动设备是否与Chrome浏览器连接。 在Web浏览器url上input以下命令

 chrome://inspect/devices#devices 

这将显示连接的设备列表。

然后设置所需的function。

以下是为我工作的代码:

 public void setUp() { File app = new File("./TestingAPK/app-release-v3.1.0-c20170201.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome"); capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); capabilities.setCapability("deviceName", "emulator-5554"); capabilities.setCapability("unicodekeyboard", true); capabilities.setCapability("resetkeyboard", true); capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "21"); capabilities.setCapability("appPackage", "app.mangalam.billboy"); capabilities.setCapability("appActivity", "app.mangalam.billboy.main.SplashActivity"); capabilities.setCapability("app", app.getAbsolutePath()); try { driver = new AndroidDriver < > (new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS); }