0
votes

Code is not able to execute on android emulator, default browser is initiated but is closed without any code execution, i get an chromedriver exception while initiating the driver itself, although i am initiating default browser on android.

I am trying to run my selenium webdriver scripts written in C# to be executed on android browser

Following is the log on Appium Server

Starting Node Server

info: Welcome to Appium v1.2.3 (REV 90d746b373f55e8653a251d2ce8c62df37941919)

info: Appium REST http interface listener started on localhost.com:4720

info: [debug] Non-default server args: {"address":"localhost.com","port":4720,"logNoColors":true,"deviceName":"AVD_for_Nexus_S","platformName":"Android","platformVersion":"18","automationName":"Appium","browserName":"Browser"}

info: Console LogLevel: debug

info: [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m [90m{"desiredCapabilities":{"browserName":"Browser","platform":"Android","version":"4.3","platformName":"Android","deviceName":"AVD_for_Nexus_S"}}[39m

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. : platform, version

info: Set mode: Proxying straight through to Chromedriver

info: [debug] Looks like we want chrome on android

info: [debug] Creating new appium session 078f2cc6-b440-4ffa-9d97-45461a4af5da

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: [debug] Checking whether adb is present

info: [debug] Using adb from C:\Android\android-sdk\platform-tools\adb.exe

info: Retrieving device

info: [debug] Trying to find a connected android device

info: [debug] Getting connected devices...

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" devices

info: [debug] 1 device(s) connected

info: Found device emulator-5554

info: [debug] Setting device id to emulator-5554

info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 wait-for-device

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 shell "echo 'ready'"

info: [debug] Starting logcat capture

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

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 install "C:\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 shell "dumpsys window"

info: [debug] Writing dumpsys output to C:\Appium\node_modules\appium.dumpsys.log

info: [debug] Screen already unlocked, continuing.

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

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 forward tcp:4724 tcp:4724

info: [debug] Pushing appium bootstrap to device...

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 push "C:\Appium\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: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 shell "ps 'uiautomator'"

info: [debug] No matching processes found

info: [debug] Running bootstrap

info: [debug] spawning: C:\Android\android-sdk\platform-tools\adb.exe -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap

info: [debug] [90m[UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1[39m

info: [debug] [90m[UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner[39m

info: [debug] [90m[UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap[39m

info: [debug] [90m[UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=[39m

info: [debug] [90m[UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:[39m

info: [debug] [90m[UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1[39m

info: [debug] [90m[UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer[39m

info: [debug] [90m[UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1[39m

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] Pushing command to appium work queue: ["getDataDir",{}]

info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.

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] dataDir set to: /data

info: [debug] Creating Chrome session

info: [debug] Set chromedriver binary as: C:\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe

info: [debug] Ensuring Chromedriver exists

info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"/data","status":0}

info: [debug] Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"9515 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %b))

info: [debug] No old chromedrivers seemed to exist

info: [debug] Spawning chromedriver with: C:\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe

info: [debug] [CHROMEDRIVER] Starting ChromeDriver (v2.10.267521) on port 9515

Only local connections are allowed.

info: [debug] Making http request with opts: {"url":"http://localhost.com:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.browser","androidActivity":"com.android.browser.BrowserActivity","androidDeviceSerial":"emulator-5554"}}}}

info: [debug] [CHROMEDRIVER STDERR] [0.008][SEVERE]: Could not bind socket to localhost.com:9515

info: [debug] [CHROMEDRIVER] Port not available. Exiting...

info: [debug] Chromedriver exited with code 1

info: [debug] Getting connected devices...

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 devices

info: [debug] 1 device(s) connected

info: [debug] executing: "C:\Android\android-sdk\platform-tools\adb.exe" -s emulator-5554 shell "am force-stop com.android.browser"

info: [debug] Stopping logcat capture

info: [debug] Logcat terminated with code null, signal SIGTERM

info: [debug] Cleaning up appium session

error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"3cf07c143b1eb3020cd100b2d72cb5c9","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86)"}}

info: [debug] Cleaning up appium session

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

info: [debug] Error: Did not get session redirect from Chromedriver

at null.<anonymous

(C:\Appium\node_modules\appium\lib\devices\android\chromedriver.js:220:12)

at Request._callback (C:\Appium\node_modules\appium\lib\devices\common.js:116:5)

at Request.self.callback (C:\Appium\node_modules\appium\node_modules\request\request.js:121:22)

at Request.EventEmitter.emit (events.js:98:17)

at Request.<anonymous

(C:\Appium\node_modules\appium\node_modules\request\request.js:985:14)

at Request.EventEmitter.emit (events.js:117:20)

at IncomingMessage.<anonymous

(C:\Appium\node_modules\appium\node_modules\request\request.js:936:12)

at IncomingMessage.EventEmitter.emit (events.js:117:20)

at _stream_readable.js:920:16

at process._tickDomainCallback (node.js:459:13)

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: [37m<-- POST /wd/hub/session [39m[31m500[39m[90m 108684.117 ms - 214[39m [90m[39m

C# Selenium code snippet:

        IWebDriver driver;
        TimeSpan timeSpan = new TimeSpan(0, 0, 300);
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.SetCapability("automationName", "Appium");
        capabilities.SetCapability(CapabilityType.BrowserName, "Browser");
        capabilities.SetCapability(CapabilityType.Platform, "Android");
        capabilities.SetCapability(CapabilityType.Version, "4.3");
        capabilities.SetCapability("platformName", "Android");
        capabilities.SetCapability("deviceName", "AVD_for_Nexus_S");
        driver = new RemoteWebDriver(new Uri("http://localhost.com:4720/wd/hub"), capabilities, timeSpan);
        driver.Navigate().GoToUrl("about:blank");
2

2 Answers

0
votes

Hey could you try running with theses capabilities that i use .. Works perfectly on my emulator and runs the tests on the android browser

    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
    capabilities.setCapability(MobileCapabilityType.PLATFORM, "Android");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Android Emulator");
    capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2");

Cheers .

0
votes

Check Chrome is installed on your emulator. It is required to run on chrome. check in the forum how to install chrome on emulator