Chrome driver fails again

Getting “org.openqa.selenium.SessionNotCreatedException: A new session could not be created” error.

following is the appium log:
info: → POST /wd/hub/session {“desiredCapabilities”:{“browserName”:“Chrome”,“platformName”:“Android”,“deviceName”:“09478d300f4133f6”}}

info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: Set mode: Proxying straight through to Chromedriver
info: [debug] Looks like we want chrome on android
info: [debug] Creating new appium session c9eefe65-966d-4e6f-bb26-d39bcbf014df
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: [debug] Checking whether adb is present
info: [debug] Using adb from D:\UD\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 cmd: D:\UD\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device 09478d300f4133f6
info: [debug] Setting device id to 09478d300f4133f6
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 wait-for-device
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “echo ‘ready’”
info: [debug] Starting logcat capture
info: [debug] Pushing unlock helper app to device…
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 install “D:\softies\Programs\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk”
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “dumpsys window”
info: Unlocking screen
info: [debug] Screen is locked, trying to unlock
info: [debug] Getting device API level
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “getprop ro.build.version.sdk”
info: [debug] Device is at API Level 22
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock”
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “dumpsys window”
info: [debug] Screen is locked, trying to unlock
info: [debug] Getting device API level
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “getprop ro.build.version.sdk”
info: [debug] Device is at API Level 22
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock”
info: [debug] [BOOTSTRAP] [debug] Emitting system alert message
info: [debug] Emitting alert message…
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “dumpsys window”
info: [debug] Screen is unlocked, continuing
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device…
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 push “D:\softies\Programs\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 cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “ps ‘uiautomator’”
info: [debug] Attempting to kill process 10627
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “kill 10627”
info: [debug] Running bootstrap
info: [debug] spawning: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap
info: [debug] UiAutomator exited
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “echo ‘ping’”
info: [debug] Attempting to uninstall app
error: UiAutomator quit before it successfully launched
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Cleaning up android objects
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] dataDir set to: /data/local/tmp
info: [debug] Creating Chrome session
info: [debug] Set chromedriver binary as: D:\softies\Programs\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [debug] Ensuring Chromedriver exists
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] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:“/data/local/tmp”}
info: [debug] No old chromedrivers seemed to exist
info: [debug] Spawning chromedriver with: D:\softies\Programs\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
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.chrome”,“androidDeviceSerial”:"09478d300f4133f6”}}}}
info: [debug] [CHROMEDRIVER STDERR] [0.013][SEVERE]: bind() returned an error: Only one usage of each socket address (protocol/network address/port) is normally permitted. (0x2740)
info: [debug] [CHROMEDRIVER] Port not available. Exiting…
info: [debug] [CHROMEDRIVER STDERR] [0.013][WARNING]: Unknown error 10038 mapped to net::ERR_FAILED
info: [debug] Chromedriver exited with code 1
info: [debug] Getting connected devices…
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 devices
info: [debug] 1 device(s) connected
info: [debug] executing cmd: D:\UD\sdk\platform-tools\adb.exe -s 09478d300f4133f6 shell “am force-stop com.android.chrome”
info: [debug] [BOOTSTRAP] [debug] Emitting system alert message
info: [debug] Emitting alert message…
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”:“0ac22d6cf7fa7ac20ea791f94e722e79”,“status”:21,“value”:{“message”:“timeout: Adb command timed out after 30 seconds\n (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86)”}}
info: [debug] Cleaning up appium session
info: [debug] Error: Did not get session redirect from Chromedriver
at null. (D:\softies\Programs\Appium\node_modules\appium\lib\devices\android\chromedriver.js:222:12)
at Request._callback (D:\softies\Programs\Appium\node_modules\appium\lib\devices\common.js:121:5)
at Request.self.callback (D:\softies\Programs\Appium\node_modules\appium\node_modules\request\request.js:121:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request. (D:\softies\Programs\Appium\node_modules\appium\node_modules\request\request.js:985:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (D:\softies\Programs\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: ← POST /wd/hub/session 500 37351.375 ms - 214
error: Failed to start an Appium session, err was: Error: Did not get session redirect from Chromedriver

Following is the code using to launch Facebook:
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

import java.io.File;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;

public class LaunchMobileBrowser
{
private AndroidDriver driver;
@BeforeTest
public void setup() throws Exception
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“deviceName”,“09478d300f4133f6”);
capabilities.setCapability(“platformName”, “ANDROID”);
capabilities.setCapability(“browserName”, “Chrome”);
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
}

 @Test
 public void launchBrowser() throws InterruptedException
 {
     driver.get("http://www.facebook.com");
     Thread.sleep(5000);
     driver.findElementByName("email").sendKeys("[email protected]");
     driver.findElementByName("pass").sendKeys("ABC");
     driver.findElementByName("login").click();
 }

}

Following is environment details:
Appium: 1.3.4.1
Chrome driver: 2.14(tried) also with 2.15
Windows 7
LG Nexus OS: 5 and 5.1

Try this:
capabilitiesAndroid.setCapability(“browserName”, “Chrome”);
capabilitiesAndroid.setCapability(“deviceName”, “Android”);
capabilitiesAndroid.setCapability(“platformName”, “Android”);
capabilitiesAndroid.setCapability(“disableAndroidWatchers”, false);
capabilitiesAndroid.setCapability(“deviceReadyTimeout”, 30);
capabilitiesAndroid.setCapability(“androidDeviceReadyTimeout”, 30);
Thread.sleep(1000);
driver = new RemoteWebDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilitiesAndroid);

And update nexus driver in system. You can find it under device manager.

When i tried below i am getting: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

     DesiredCapabilities capabilities = new DesiredCapabilities();
     capabilities.setCapability("deviceName","09478d300f4133f6");
     capabilities.setCapability("platformName", "ANDROID");
     capabilities.setCapability("browserName", "Chrome");
     capabilities.setCapability("disableAndroidWatchers", false);
     capabilities.setCapability("deviceReadyTimeout", 30);
     capabilities.setCapability("androidDeviceReadyTimeout", 30);
     driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

@jlipps, can you throw some light? any pointers? etc… My work is blocked because of this.

I think @isaac is working on a fix.

Even i am struggling with this since last 2 days…still not able to lauch chrome browse. tried various possibilities like

  1. started server on 127.0.0.1:4723
  2. started server on 0.0.0.0:4723
  3. started server on 127.0.0.1:9515
  4. started server on 0.0.0.0:9515

Till the fix is released use:

Package = com.android.chrome

Launch Activity = com.google.android.apps.chrome.document.ChromeLauncherActivity

unckeck the use browser and use these parameters and launch appium and

				DesiredCapabilities capabilities = new DesiredCapabilities();
				capabilities = DesiredCapabilities.android();
				capabilities.setCapability("browserName", "Browser");
				capabilities.setCapability("platformName", "Android");
				capabilities.setCapability("platformVersion", "4.4.2");
				capabilities.setCapability("automationName", "Appium");
				capabilities.setCapability("device", "Android");
				capabilities.setCapability("app", "chrome");

On which url are you launching appium driver server ?

i tried these desired capabilities and found the ECONNREFUSED again.

I started server on

  1. http://0.0.0.0:4723/wd/hub
    2.http://127.0.0.1:4723/wd/hub
    2.http://127.0.0.1:9515/wd/hub

Are you using android Chrome app or native android browser ?

You can start appium server on any port until unless its not already in use. Letz try something else:

Instead of using the capabilities letz first see if you are able to launch chrome on your device from appium.

  1. Use the package name and Activity name in appium app
  2. enter the device name
  3. launch appium.
  4. Click on “Inspector” and see if your device launches chrome browser.

I am trying this code on Windows so inspector does not work, Any alternative for step 4 ? I tried both Native and Chrome browser

I know what the problem is.

You need to close the chrome.exe from your task manager, This is a windows problem that it start the chrome.exe and but never closes it if ur test aborts. Close it and then try the snippet.

ChromeBatch.txt (60 Bytes)

Download this file and change it to .exe instead of txt and run it before you start your test.

and add these capabilitites in your test

capabilities.setCapability(“appPackage”, “com.android.chrome”);
capabilities.setCapability(“appActivity”, “com.google.android.apps.chrome.document.ChromeLauncherActivity”);

Attaching logs with this post.
Code is as follows.
Tried downloading and running that file but could not run .Screenshot of error is also attached

logs.txt (10.1 KB)

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities = DesiredCapabilities.android();
	capabilities.setCapability("browserName", "Browser");
	capabilities.setCapability("platformName", "Android");
	capabilities.setCapability("platformVersion", "4.4.2");
	capabilities.setCapability("automationName", "Appium");
	capabilities.setCapability("deviceName", "Android");
	capabilities.setCapability("disableAndroidWatchers", false);
	capabilities.setCapability("deviceReadyTimeout", 30);
	capabilities.setCapability("androidDeviceReadyTimeout", 30);
	capabilities.setCapability("app", "chrome");
	capabilities.setCapability("appPackage", "com.android.chrome");
	capabilities.setCapability("appActivity", "com.google.android.apps.chrome.document.ChromeLauncherActivity");
	
	try {

driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),capabilities);
driver.get(“https://www.google.co.in/”);
}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

As anish said, just make sure kill chromedriver.exe process and also any adb.exec processes from the task bar before you re-run the scripts.

As appium starts this process when it starts executing the script with chromebrowser, appium has to fix this issue by killing this process from taskbar in case of any Exception or Abrupt script termination.

There is a fix for this in Appium 1.4.0, Download that.

Also if that batch file is not working, try to kill it from your system tools.

I run the script first time…there was no adb.exe processes and also the chromedriver.exe… no success with that run

In next run i killed both (adb and chromedriver) but still no success…

@Anish_ohri : For your comment -There is a fix for this in Appium 1.4.0, Download that.- I am working with 1.4.0 only

I visited github…1.4.1 to 1.4.3 are in beta state…i downloaded the .zip file of source code. If i want to run that version of appium (e.g. 1.4.1 ) how to work with that…I am new to all this stuff.so this may sound silly :frowning: …Let me know how to work with these releases for WINDOWS

Latest releases are always on npm. This is the most reliable source. If you don’t now npm there is a tutorial here:

What i did (working on WINDOWS)
-uninstalled the appium 1.4.0
-placed Appium-1,4,1 folder at some locaiton
-from bin folder (of the Appium-1.4.1 folder) fired command
npm install -g appium

  • it gave me error as

34 error network tunneling socket could not be established, cause=connect ECONNREFUSED
34 error network This is most likely not a problem with npm itself
34 error network and is related to network connectivity.
34 error network In most cases you are behind a proxy or have bad network settings.

I searched about http_proxy and https_proxy parameter. added new environmental variable. http_proxy=http://username:password@hostname:port;

but can’t understand what to set for hostname:port.
Please help me and check if these steps are correct or not

Hey I use to run into something similar. When I run the Android tests multiple times, the test would fail because it could not connect to the device. I opened a bug with ChromeDriver:

https://code.google.com/p/chromedriver/issues/detail?id=1225

They have fixed this in the latest 2.20 version. Hope that helps.