Android Stock Browser - Will it work on real devices with API 4.4+?

Hi All,

I am trying to run a simple web test on Android stock browser. Now that Chrome is bundled with Appium, even though the capability is set to “Browser” as mentioned in the documentation, I am not able to launch the browser and run my test. I am using Android 4.4 real device.

Below is my code snippet. Kindly let me know where am doing wrong…

One thing I don’t understand is that, when I define the browser to be Stock browser, why does Appium trying to open a session using chrome driver on “127.0.0.1:9515” and failing?

I want to update myself on the capability of Appium to run tests on Android Stock browser.

Code Snippet:

package com.appium.qa;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.android.AndroidDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class StockBrowserAppium {
public static void main(String[] args) {
AppiumDriver driver;
try {

        DesiredCapabilities capabilities = new DesiredCapabilities();   
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "Browser");
        capabilities.setCapability(CapabilityType.VERSION, "4.4");
         capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("deviceName", "GalaxyS4");
        
        URL AppiumDriver = new URL("http://127.0.0.1:4723/wd/hub");
        driver = (AppiumDriver) new RemoteWebDriver(AppiumDriver, capabilities);
        driver.get("http://www.yahoo.com");
        
        /*DesiredCapabilities capabilities = DesiredCapabilities.android();
        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.2");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"GalaxyS4");
                
        URL AppiumDriver = new URL("http://127.0.0.1:4723/wd/hub");
        driver = (AppiumDriver) new RemoteWebDriver(AppiumDriver, capabilities);
        
        driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
        driver.get("http://www.yahoo.com");*/
            
    }
    catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

Appium Log:

Launching Appium with command: export ANDROID_HOME="/Users/914862/Documents/MobileAutomation/adt-bundle-mac-x86_64-20140702/sdk"; ‘/Applications/Appium.app/Contents/Resources/node/bin/node’ lib/server/main.js --address “127.0.0.1” --callback-address “127.0.0.1” --callback-port “4723” --command-timeout “7200” --session-override --log “/tmp/appium.log” --automation-name “Appium” --platform-name “Android” --platform-version “4.4” --app “browser” --browser-name “Browser”

info: Welcome to Appium v1.3.5 (REV a124a15677e26b33db16e81c4b3b34d9c6b8cac9)

info: Appium REST http interface listener started on 127.0.0.1:4723

info: [debug] Non-default server args: {“app”:“browser”,“address”:“127.0.0.1”,“callbackAddress”:“127.0.0.1”,“callbackPort”:4723,“sessionOverride”:true,“log”:"/tmp/appium.log",“platformName”:“Android”,“platformVersion”:“4.4”,“automationName”:“Appium”,“browserName”:“Browser”,“defaultCommandTimeout”:7200}

info: Console LogLevel: debug

info: File LogLevel: debug

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.5”,“revision”:“a124a15677e26b33db16e81c4b3b34d9c6b8cac9”}}}

info: <-- GET /wd/hub/status 200 10.769 ms - 104 {“status”:0,“value”:{“build”:{“version”:“1.3.5”,“revision”:“a124a15677e26b33db16e81c4b3b34d9c6b8cac9”}}}

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.5”,“revision”:“a124a15677e26b33db16e81c4b3b34d9c6b8cac9”}}}

info: <-- GET /wd/hub/status 200 2.857 ms - 104 {“status”:0,“value”:{“build”:{“version”:“1.3.5”,“revision”:“a124a15677e26b33db16e81c4b3b34d9c6b8cac9”}}}

info: --> POST /wd/hub/session {“desiredCapabilities”:{“deviceName”:“OfficeflipS4”,“platformName”:“Android”,“browserName”:“Browser”,“version”:“4.4”}}

info: Client User-Agent string: Apache-HttpClient/4.3.6 (java 1.5)

info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : version
info: Set mode: Proxying straight through to Chromedriver
info: [debug] Looks like we want chrome on android
info: [debug] Creating new appium session b3aafa35-56be-4c21-af87-0d5aa6b4bcac
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it’s already on the device
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices…
info: [debug] executing cmd: adb devices

info: [debug] 1 device(s) connected

info: Found device 4d00be06e9ae4093
info: [debug] Setting device id to 4d00be06e9ae4093
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: adb -s 4d00be06e9ae4093 wait-for-device

info: [debug] executing cmd: adb -s 4d00be06e9ae4093 shell “echo ‘ready’”

info: [debug] Starting logcat capture

info: [debug] Pushing unlock helper app to device…

info: [debug] executing cmd: adb -s 4d00be06e9ae4093 install “/Applications/Appium.app/Contents/Resources/node_modules/appium/build/unlock_apk/unlock_apk-debug.apk”

info: [debug] executing cmd: adb -s 4d00be06e9ae4093 shell “dumpsys window”

info: [debug] Screen already unlocked, continuing.

info: [debug] Forwarding system:4724 to device:4724

info: [debug] executing cmd: adb -s 4d00be06e9ae4093 forward tcp:4724 tcp:4724

info: [debug] Pushing appium bootstrap to device…
info: [debug] executing cmd: adb -s 4d00be06e9ae4093 push “/Applications/Appium.app/Contents/Resources/node_modules/appium/build/android_bootstrap/AppiumBootstrap.jar” /data/local/tmp/

info: Starting App

info: [debug] Attempting to kill all ‘uiautomator’ processes
info: [debug] Getting all processes with ‘uiautomator’
info: [debug] executing cmd: adb -s 4d00be06e9ae4093 shell “ps ‘uiautomator’”

info: [debug] No matching processes found

info: [debug] Running bootstrap

info: [debug] spawning: adb -s 4d00be06e9ae4093 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap

info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1

info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=

info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1

info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json…
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] Pushing command to appium work queue: [“getDataDir”,{}]
info: [debug] [BOOTSTRAP] [debug] Client connected
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“getDataDir”,“params”:{}}

info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
info: [debug] [BOOTSTRAP] [debug] Returning result: {“value”:"/data/local/tmp",“status”:0}
info: [debug] dataDir set to: /data/local/tmp
info: [debug] Creating Chrome session
info: [debug] Set chromedriver binary as: /Applications/Appium.app/Contents/Resources/node_modules/appium/build/chromedriver/mac/chromedriver
info: [debug] Ensuring Chromedriver exists
info: [debug] Killing any old chromedrivers, running: ps -ef | grep /Applications/Appium.app/Contents/Resources/node_modules/appium/build/chromedriver/mac/chromedriver | grep -v grep |grep -e ‘–port=9515(\s.*)?$’ | awk ‘{ print $2 }’ | xargs kill -15

info: [debug] Successfully cleaned up old chromedrivers
info: [debug] Spawning chromedriver with: /Applications/Appium.app/Contents/Resources/node_modules/appium/build/chromedriver/mac/chromedriver

info: [debug] [CHROMEDRIVER] Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 9515
Only local connections are allowed.

info: [debug] Making http request with opts: {“url”:“http://127.0.0.1:9515/wd/hub/session",“method”:“POST”,“json”:{“sessionId”:null,“desiredCapabilities”:{“chromeOptions”:{“androidPackage”:“com.android.browser”,“androidActivity”:“com.android.browser.BrowserActivity”,“androidDeviceSerial”:"4d00be06e9ae4093”}}}}

info: [debug] Cleaning up appium session

info: [debug] Error: Did not get session redirect from Chromedriver
at null. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/chromedriver.js:222:12)
at Request._callback (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/common.js:121:5)
at Request.self.callback (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/request/request.js:121:22)
at Request.emit (events.js:110:17)
at Request. (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/request/request.js:985:14)
at Request.emit (events.js:129:20)
at IncomingMessage. (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/request/request.js:936:12)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickDomainCallback (node.js:381:11)

error: Chromedriver create session did not work. Status was 200 and body was {“sessionId”:“a69b0794f84f8abad094b6001717d1a6”,“status”:13,“value”:{“message”:“unknown error: com.android.browser is not installed on device 4d00be06e9ae4093\n (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.9.5 x86_64)”}}

info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: Did not get session redirect from Chromedriver)”,“origValue”:“Did not get session redirect from Chromedriver”},“sessionId”:null}
info: <-- POST /wd/hub/session 500 7085.743 ms - 214

error: Failed to start an Appium session, err was: Error: Did not get session redirect from Chromedriver

I have seen some post with same issues but then, no work around or solution has been provided. It has been blindly said to use the “browserName” to “Browser” which is not the working though.

Could anyone help on how to get the stock browser automated to run web tests?

Many Thanks…!!
Regards,
mkvignesh

@mkvignesh

Hi do u get any solution for automate android stock Browser ?