10
votes

I am trying to run my first test through Appium and getting the below error.

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Did not get session redirect from Chromedriver) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 4.64 seconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51'
Driver info: org.openqa.selenium.remote.RemoteWebDriver

Appium Logs:

ERROR: debug: Appium request initiated at /wd/hub/session
info: Looks like we want chrome on android
info: Creating new appium session 99ff77a0-86fa-4851-93ad-5375c95656e7
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" devices
info: Preparing device for session
info: Not checking whether app is present since we are assuming it's already on the device
info: Checking whether adb is present
info: [ADB] Using adb from D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe
info: Trying to find a connected android device
info: [ADB] Getting connected devices...
info: [ADB] 1 device(s) connected
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 wait-for-device
info: Setting device id to emulator-5554
info: [ADB] Waiting for device to be ready and to respond to shell commands (timeout = 5)
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 shell "echo 'ready'"
info: Starting logcat capture
ERROR: debug: Pushing unlock helper app to device...
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 install "C:\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 shell "dumpsys window"
info: Writing dumpsys output to C:\Appium\node_modules\appium\.dumpsys.log
ERROR: debug: Screen already unlocked, continuing.
info: Creating Chrome session
info: Ensuring Chromedriver exists
info: 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: No old chromedrivers seemed to exist
info: Spawning chromedriver with: C:\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [CHROMEDRIVER] Starting ChromeDriver (v2.9.248315) on port 9515
info: Making http request with opts: {"url":"http://****:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.browser","androidActivity":"com.android.browser.BrowserActivity","androidDeviceSerial":"emulator-5554"}}}}
ERROR: debug: executing: "D:\****\adt-bundle-windows-x86-20140321\sdk\platform-tools\adb.exe" -s emulator-5554 devices
info: [CHROMEDRIVER STDERR] [0.003][SEVERE]: Could not bind socket to 0.0.0.0:9515
info: [CHROMEDRIVER] Port not available. Exiting...
info: Chromedriver exited with code 1
info: [ADB] Getting connected devices...
ERROR: error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"ba9a494082776d6b4836da850072cbcb","status":13,"value":{"message":"unknown error: Device emulator-5554 is already in use\n (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86)"}}
info: Cleaning up appium session
ERROR: error: Failed to start an Appium session, err was: Error: Did not get session redirect from Chromedriver
info: Error: Did not get session redirect from Chromedriver
at null. (C:\Appium\node_modules\appium\lib\devices\android\chromedriver.js:195:12)
at Request._callback (C:\Appium\node_modules\appium\lib\devices\common.js:104: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. (C:\Appium\node_modules\appium\node_modules\request\request.js:985:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (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._tickCallback (node.js:415:13)
info: 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}

I want to use only Android default Browser and not Chrome. I dont know why Appium is trying to launch Chromedriver and Chrome Browser. Below is the code i used.

import java.net.URL;                

import org.openqa.selenium.WebDriver;                
import org.openqa.selenium.remote.CapabilityType;                
import org.openqa.selenium.remote.DesiredCapabilities;                
import org.openqa.selenium.remote.RemoteWebDriver;                
import org.testng.annotations.AfterMethod;                
import org.testng.annotations.BeforeMethod;                
import org.testng.annotations.Test;                

public class Appium {                

    public WebDriver driver;            

    @BeforeMethod            
    public void beforeMethod() throws Exception {            
        // set up appium        
        DesiredCapabilities capabilities = new DesiredCapabilities();        
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "Browser");        
        capabilities.setCapability("platformName", "Android");        
        capabilities.setCapability("deviceName", "Android Emulator");        
        capabilities.setCapability("platformVersion", "4.4.2");        
        WebDriver driver = new RemoteWebDriver(new URL(        
                http://****:4723/wd/hub), capabilities);
        driver.get("http://www.yahoo.com");        
    }            

    @Test            
    public void f() {            

    }            

    @AfterMethod            
    public void afterMethod() {            
        driver.quit();        
    }            

}
5
Getting the same error? You got any solution?HemaSundar

5 Answers

1
votes

You need to set the below URL to http://0.0.0.0:9515/wd/hub instead of ****:4723...

WebDriver driver = new RemoteWebDriver(new URL(http://****:4723/wd/hub), capabilities);

Chromedriver's port defaults to 9515, not 4723. You should read the documentation on this. There are other capabilities that need to be set correctly (like BROWSER_NAME)

0
votes

The safest way to set for android capabilities = DesiredCapabilities.android()

PS: You got session is not created because your script is not able to connect to selenium node/hub; you should check your configuration

As in your post stacktrace, it connects to http://**:9515/ (not like in your mentioned port 4723)

0
votes

Though this issue is quite an old one and a lot of definition has changed on appium client usage along with the chrome driver version updates as well. Yet to what I could figure out was that the issue here was this from the logs :

ERROR: error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"ba9a494082776d6b4836da850072cbcb","status":13,"value":{"message":"unknown error: Device emulator-5554 is already in use\n (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86)"}}

which resulted further into :

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Did not get session redirect from Chromedriver) (WARNING: The server did not provide any stacktrace information)

and hence SessionNotCreatedException.

Simpler fix to this could be ensuring no other session is in progress before initiating another to avoid conflicts of ports and session failure.

0
votes

Try running after commenting below statement

 capabilities.setCapability("platformVersion", "4.4.2"); 
0
votes

Replace old chrome driver to new chrome driver in appium location, it worked for me.

The Appium location should be something like:

C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\

Appium version : 1.4.16.1