How can I use selenium or appium to automate chrome browser on android?

31,557

Solution 1

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

If nothing is happening here, then you must restart your ARM emulator and the appium server/chromedriver again. I came across this multiple times and noticed many a times adb shuts down and looses connectivity. If I restart abd, everything starts working. This is just a adb command to install the apk, it should take time depending on the size of the apk but not much.

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");
}

I have this piece of code which runs well on appium automating the android chrome browser. In the above log, you chromedriver has not started successfully and so the browser is not automated. I have appium log which is automating the chrome browser: enter image description here Also, every combination of ChromeDriver and Chrome APK is not working. I have been struggling this since days and found out that: Chrome Driver 2.3 and Chrome APK 29.xxx are compatible. Chrome Driver 2.9/2.8 and Chrome APK 30.xx or 31.xx are not working.

Regarding Just ChromeDriver: The chromium link you mentioned will automate the PC browser if you have not set the capability. Something like this:

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

You have to set this capability incase you are just using chromedriver (and not appium). I am working on this but could not find the capability. Also you will have to start the ChromDriver by yourself on command promt which will listen at 9515 port for any automation.

Solution 2

1) Read appium logs and see what version of chrome driver is it referring to. 2) Check online for latest chromedriver version. As of today latest version is 2.23. Download this for WindowsAnd extract it http://chromedriver.storage.googleapis.com/index.html?path=2.23/ 3) Upgrade Appium (latest today - 1.4.16.1) Now goto this location, C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win

And paste the the chromedriver.exe here.(replace the old one)

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) In case this does not work, make sure to check in appium logs, if its pointing to the updated chrome version

Share:
31,557
Juan Acevedo
Author by

Juan Acevedo

Updated on July 09, 2022

Comments

  • Juan Acevedo
    Juan Acevedo almost 2 years

    I am trying to automate the android Chrome browser on an android device (not just a webview or another browser, but Chrome browser). I thought this was possible by following this link https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android but it automates my pc chrome browser instead.

    I also tried Appium, but nothing happens after the log:

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

    And when I try to access info from the browser, I get this:

    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"}
    

    I do have chromedriver.exe in my environment variable PATH, the whole log looks like this:

    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
    

    Thank you.

  • Juan Acevedo
    Juan Acevedo over 10 years
    Thank you. I ended up creating my own webview in 4.4 android that can connect to chrome tools. I am sure this works, because I seen the same logs you just put on other sites, but for me it just freezes at the unlock_apk-debug.apk. Restarting adb doesn't help. Also, I am using a phone, not an emulator.
  • Khushboo
    Khushboo over 10 years
    If your appium log freezes at unlock...statement, you might probably have more than one connected device...Also you can simply execute this command separately with any arbitary apk file to check what is wrong with your adb.
  • mojjj
    mojjj almost 10 years
    maybe disable "app verification via USB" in settings/developer options on the device might help? also more than one device (real or emulator) might cause problems
  • djleop
    djleop about 4 years
    your answer does not add anything to the original answer, can you explain how your answer is better than the actual accepted answer ?