org.openqa.selenium.remote.SessionNotFoundException: Session ID is null

11,626 views
Skip to first unread message

Anuja Rokade

unread,
Sep 18, 2013, 2:30:09 PM9/18/13
to webd...@googlegroups.com
Hi,

I am running my Webdriver-TestNG script on Linux machine as Hub, same m/c as node and Windows m/c as node. So a hub and 2 nodes.
I am running the script in parallel, with 2 data sets provided by my CSV file.

So on each machine opens 2 firefox and run the scripts in parallel. First two times the script will run successfully on each and for second it's throwing
"org.openqa.selenium.remote.SessionNotFoundException: Session ID is null"


org.openqa.selenium.remote.SessionNotFoundException: Session ID is null
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-358.2.1.el6.x86_64', java.version: '1.6.0_24'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:276)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:724)
    at Selenium_Wellbeing.WellbeingTest.runnewtest(WellbeingTest.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:73)
    at org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:14)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)

Any help is really appreciated.


Krishnan Mahadevan

unread,
Sep 24, 2013, 3:20:22 AM9/24/13
to webdriver
Anuja,

Initial look at the stacktrace
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:276)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:724)
    at Selenium_Wellbeing.WellbeingTest.runnewtest(WellbeingTest.java:40)

seems to suggest that you perhaps are encountering a Thread mixup here. You tried operating on a WebDriver for which WebDriver.quit() has already been called which causes the Grid to nullify that particular session and then somewhere else you are trying to use that "stale session" which is causing this error.

You would need to show us the code you are using to create your RemoteWebDriver instance for every given thread.








Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/groups/opt_out.

LearningSelenium

unread,
Sep 24, 2013, 2:54:22 PM9/24/13
to webd...@googlegroups.com
Thanks for the reply.
 
I am using below code:
 
 
WebDriver driver;

@BeforeMethod()

public void launchbrowser() {

driver = new FirefoxDriver();

}

@AfterMethod

public void closebrowser() {

driver.close();

driver.quit();

}

I have added this code in one class which my main class extends.

Thanks,

Anuja

Luke Inman-Semerau

unread,
Sep 24, 2013, 3:26:40 PM9/24/13
to webd...@googlegroups.com
if you're calling driver.quit(); there's no reason to call driver.close();

if you only have one window open, driver.close() will effectively quit
your session and thus the next call to driver.quit(); will fail.
While .quit() will close all windows open.

just change your AfterMethod to just have driver.quit();

LearningSelenium

unread,
Sep 24, 2013, 5:23:55 PM9/24/13
to webd...@googlegroups.com
Thanks Luke.
 
I think this resolved the issue when i am not adding "parallel=true" in dataprovider. But if i am using "parallel=true" in dataprovider, it gives me same error.
 
So this takes me to next array of questions, (I would like to add this in new thread, but not sure how to summarise)
 
If I have username and pwd in CSV file, so if there are only two data items and I am adding parallel=true in dataprovider.
 
It runs both login on both nodes (I am trying to run my script on a hub and 2 nodes) in parallel.
 
So at the same time with same first username and pwd, it will run the script on both nodes. and the same for 2 data item.
 
How I can ask grid to keep taking the next data items in CSV file every time.
 
 
(And i think as it is trying to run the script with same credentials at the same time in different browsers, i am finding above issues)
 
Thanks

Marcus Merrell

unread,
Sep 24, 2013, 5:34:34 PM9/24/13
to webd...@googlegroups.com
I could be wrong, but I think we've had a similar problem to this when the TestNG data provider is involved--I *believe* the @BeforeMethod and @AfterMethod tasks take place in different threads from the main test threads... so when you use parallel dataProvider threads with grid, the thread that set up the browser ends up being different from the thread that manages it for the test, so it doesn't "see" the same browser session IDs. Someone correct me if this is wrong, but it seems like we ran into this issue a while back and ended up having to write quite a bit of thread handling code to correct for it.

If this turns out to be correct, I'd like to figure out how to package up the solution--as far as I know TestNG doesn't consider it to be a problem
MM

LearningSelenium

unread,
Sep 26, 2013, 2:02:02 PM9/26/13
to webd...@googlegroups.com
Thanks MM.

Being not a developer, I have less knowledge about the code logic behind @AfterMethod/@BeforeMethod/ the thread handling in webdriver.

Any insights from experts are welcome.

Thanks,
Anuja

Marcus Merrell

unread,
Sep 26, 2013, 2:10:11 PM9/26/13
to webd...@googlegroups.com
Have you tried rolling the code from the before and after methods into the beginning/end of your test method? I'd be curious to see if that works for you... just remove the before/after methods and put that code right there with the test--that should guarantee that they're all in the same thread. It's worth a try just for sanity's sake.
MM

LearningSelenium

unread,
Sep 26, 2013, 4:39:36 PM9/26/13
to webd...@googlegroups.com
Thanks MM. I will try this.

Anuja

Ashish Gijare

unread,
Jan 5, 2015, 2:00:35 AM1/5/15
to webd...@googlegroups.com
Hi,

I know its very old thread but i am facing the same issue. Can you please describe solution for this issue.

Thanks in Advance!!

Krishnan Mahadevan

unread,
Jan 5, 2015, 11:33:57 PM1/5/15
to webdriver
Ashish,

Since this is indeed a very old thread, can you please add some current context to this problem ?

How are you starting up your node, grid etc.,
How does your WebDriver instantiation code look like ?

How does a typical 2 test methods which are to be running in parallel look like ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

Trinadh Kumar

unread,
Jun 20, 2017, 3:44:24 AM6/20/17
to webdriver
HI , 

I am facing the same issue when i implemented parallel run with Thread Local concept and TestNg. Any help on this would help me.
Reply all
Reply to author
Forward
0 new messages