ERROR - A new session could not be created for android appium

Hi All ,

Getting the below error when i am running selenium based grid in appium ,

ERROR

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 121 milliseconds
Build info: version: ‘2.43.1’, revision: ‘5163bceef1bc36d43f3dc0b83c88998168a363a0’, time: ‘2014-09-10 09:43:55’
System info: host: ‘LM-sjn-00877356’, ip: ‘10.244.65.221’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.1’, java.version: ‘1.7.0_71’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at com.paypal.selion.android.sample.AndroidGrid.main(AndroidGrid.java:63)

APPIUM NODE CONSOLE :

COMMAND : appium --nodeconfig /Users/mselvansr/grid/android1.json -p 4728
info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
info: Appium REST http interface listener started on 0.0.0.0:4728
info: [debug] Non-default server args: {“port”:4728,“nodeconfig”:"/Users/mselvansr/grid/android1.json"}
info: Console LogLevel: debug
info: [debug] starting auto register thread for grid. Will try to register every 5000 ms.
info: [debug] Appium successfully registered with the grid on 127.0.0.1:4433
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.4”,“revision”:“c8c79a85fbd6870cd6fc3d66d038a115ebe22efe”}}}
info: <-- GET /wd/hub/status 200 3.230 ms - 104 {“status”:0,“value”:{“build”:{“version”:“1.3.4”,“revision”:“c8c79a85fbd6870cd6fc3d66d038a115ebe22efe”}}}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.4”,“revision”:“c8c79a85fbd6870cd6fc3d66d038a115ebe22efe”}}}

NODE CONFIGURATION : Configured in port 4728

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“5.0”,
“maxInstances”: 3,
“platform”:“ANDROID”,
“deviceName”:“emulator-5554”
}
],
“configuration”:{
“cleanUpCycle”:2000,
“timeout”:30000,
“proxy”:“org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4728/wd/hub”,
“host”:“127.0.0.1”,
“port”:4728,
“maxSession”:1,
“register”:true,
“registerCycle”:5000,
“hubPort”:4433,
“hubHost”:“127.0.0.1”
}
}

SELENIUM GRID CONSOLE :

java -jar /Users/mselvansr/Downloads/selenium-server-standalone-2.44.0.jar -role hub -port 4433
22:12:46.889 INFO - Launching a selenium grid server
2015-01-25 22:12:47.514:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2015-01-25 22:12:47.547:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2015-01-25 22:12:47.553:INFO:osjs.AbstractConnector:Started [email protected]:4433

Source code for running android emulator :

DesiredCapabilities capabilities = new DesiredCapabilities();
File appDir = new File("/Users/mselvansr/Developer");
File app = new File(appDir, “AndroidPdfViewer_1_0_0b.apk”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,“Android”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “emulator-5554”);
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);
try {
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4728/wd/hub”), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
System.out.println(“App launched”);

ERROR :

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 121 milliseconds
Build info: version: ‘2.43.1’, revision: ‘5163bceef1bc36d43f3dc0b83c88998168a363a0’, time: ‘2014-09-10 09:43:55’
System info: host: ‘LM-sjn-00877356’, ip: ‘10.244.65.221’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.1’, java.version: ‘1.7.0_71’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at com.paypal.selion.android.sample.AndroidGrid.main(AndroidGrid.java:63)

COMMAND FOR ADB STATUS -CONNECTED
adb devices
List of devices attached
emulator-5554 device

CLARIFICATIONS and NEED SOLUTION PLEASE :

My grid and node is started successfully and i am passing all the required DesiredCapabilities for starting android emulator then why i am getting this error and not able to start my app in emulator , HELP ME PLEASE

My knowledge only goes so far, but instead of pre-launching the emulator, try setting the deviceName in the node config to be the name of the AVD, not the name of the running emulator.

e.g. If you have an AVD named nexus5, it may run as emulator-5554, but if you give Appium “nexus5” as the deviceName then it should automatically launch and use that AVD without you having to launch the emulator manually.

There’s also the appium server flag --avd.
e.g. appium --avd nexus5

Hi Hysistia ,

Added the following capabilities but still getting the error

// first is my avd name
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “first”);

Error :
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 126 milliseconds
Build info: version: ‘2.43.1’, revision: ‘5163bceef1bc36d43f3dc0b83c88998168a363a0’, time: ‘2014-09-10 09:43:55’
System info: host: ‘N/A’, ip: ‘N/A’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.1’, java.version: ‘1.7.0_71’
Driver info: org.openqa.selenium.remote.RemoteWebDriver

Config File :

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“5.0.1”,
“maxInstances”: 3,
“platform”:“ANDROID”,
“deviceName”:“first”
}
],
“configuration”:{
“cleanUpCycle”:2000,
“timeout”:30000,
“proxy”:“org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4728/wd/hub”,
“host”:“127.0.0.1”,
“port”:4728,
“maxSession”:1,
“register”:true,
“registerCycle”:5000,
“hubPort”:4433,
“hubHost”:“127.0.0.1”
}
}

Confirmation :

Could you please confirm , What is wrong ? Why my app is not launched ? even device in connected status ?

Thanks ,
Muthu Selvan SR

Hi Muthu, if I have time today, I’ll try testing your capabilities and node config on my PC briefly.

Thanks Hysistia , Appreciate your help !

FYI , Getting the below log in appium node :

info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices…
info: [debug] executing cmd: “/usr/local/bin/adb” 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 cmd: “/usr/local/bin/adb” -s emulator-5554 wait-for-device
info: [debug] executing cmd: “/usr/local/bin/adb” -s emulator-5554 shell “echo ‘ready’”
info: [debug] Starting logcat capture
error: Logcat capture failed: spawn ENOENT
info: [debug] Stopping logcat capture
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.4”,“revision”:“c8c79a85fbd6870cd6fc3d66d038a115ebe22efe”}},“sessionId”:“6439590d-f2c5-45af-861a-d92458c15012”}
info: <-- GET /wd/hub/status 200 0.591 ms - 155 {“status”:0,“value”:{“build”:{“version”:“1.3.4”,“revision”:“c8c79a85fbd6870cd6fc3d66d038a115ebe22efe”}},“sessionId”:“6439590d-f2c5-45af-861a-d92458c15012”}
info: --> GET /wd/hub/status {}

Thanks Hysistia . its working fine after i set correct ANDROID_HOME in PATH before running the appium …

You’re welcome; unfortunately I didn’t get around to testing yesterday. I’m glad it’s working! :smile:

Hysistia ,

I am looking your help on my below issue

I am having the same issue trying to run on Android emulator. My ANDROID_HOME is set correctly. Appium Inspector can launch the app properly, but cannot run tests from terminal. Would appreciate your help.

mahvish:imoji mahvish$ CAP=capabilities.android.testing behave
2015-10-02 17:19:48.817076:FBLoginWeb: **** Inside fb login web view setting cancel
2015-10-02 17:19:48.842771:before_all{‘context’: <behave.runner.Context object at 0x10c788d90>}:None
@debuglogin
Feature: Login with Email # features/debuglogin.feature:3
As email-registered user
I want to login
so that I can use the app2015-10-02 17:19:48.844196:connect:remote with:{‘appPackage’: ‘com.bitstrips.imoji.testing’, ‘autoLaunch’: True, ‘platformName’: ‘Android’, ‘deviceName’: ‘Android’}
Traceback (most recent call last):
File “/usr/local/bin/behave”, line 8, in
load_entry_point(‘behave==1.2.4’, ‘console_scripts’, ‘behave’)()
File “build/bdist.macosx-10.9-intel/egg/behave/main.py”, line 111, in main
File “build/bdist.macosx-10.9-intel/egg/behave/runner.py”, line 659, in run
File “build/bdist.macosx-10.9-intel/egg/behave/runner.py”, line 680, in run_with_paths
File “build/bdist.macosx-10.9-intel/egg/behave/runner.py”, line 481, in run_model
File “build/bdist.macosx-10.9-intel/egg/behave/model.py”, line 447, in run
File “build/bdist.macosx-10.9-intel/egg/behave/runner.py”, line 403, in run_hook
File “/Users/mahvish/src/disco/imoji/features/environment.py”, line 38, in before_feature
context.app.connect()
File “features/steps/support/app.py”, line 16, in connect
self.wd = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, self.capabilities)
File “build/bdist.macosx-10.10-intel/egg/appium/webdriver/webdriver.py”, line 35, in init
File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 73, in init
self.start_session(desired_capabilities, browser_profile)
File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 121, in start_session
‘desiredCapabilities’: desired_capabilities,
File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 173, in execute
self.error_handler.check_response(response)
File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py”, line 164, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u’A new session could not be created. (Original error: spawn “/usr/local/bin/adb” ENOENT)’
mahvish:imoji mahvish$

HI All,

I am getting below error while trying to run below appium code.Checked all possible solutions but not getting it resolved.:-

ERROR

Exception in thread “main” org.openqa.selenium.remote.SessionNotFoundException:
Command duration or timeout: 610 milliseconds
Build info: version: ‘2.53.0’, revision: ‘35ae25b’, time: ‘2016-03-15 17:00:58’
System info: host: ‘INDC5WWGY1’, ip: ‘10.135.161.85’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_67’
Session ID: eaffbafa14995946ea8e119fb1539160
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{platform=ANDROID, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=44.0.2403.119, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=true, applicationCacheEnabled=false, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:268)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:526)
at appium.My.main(My.java:38)

Please do someone quote on this for below code :

Code

package appium;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileBrowserType;
import io.appium.java_client.remote.MobileCapabilityType;

public class My {

            public static void main(String[] args) throws MalformedURLException {
                            // TODO Auto-generated method stub
                            AndroidDriver driver;

                            DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "Nexus 5");
    capabilities.setCapability("platformName", "android");
    capabilities.setCapability("platformVersion", "5.0.1");
    
    
      capabilities.setCapability("appPackage","com.android.calculator2");
      capabilities.setCapability("appActivity","com.android.calculator2.Calculator");
                           
    
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
   
    driver.quit();

            }

Hi,

Even I have this issue how to fix it?

I had similar issue and i got it fixed with

1> Make sure “PORT” address is the same in

2> Make sure Device name in adb devices and in Appium settings are the same

example -
in adb devices : -
user adb devices
List of devices attached
emulator-5554 device

in Appium :-
Device Name = emulator-5554