Web Testing using Selenium – fix for error “java.lang.NullPointerException: sessionId should not be null; has this session been started yet?” « Intelligrape Groovy & Grails Blogs

Web Testing using Selenium – fix for error “java.lang.NullPointerException: sessionId should not be null; has this session been started yet?”

Posted by admin

I have a big fan of Selenium and have been using Selenium for quite some time for testing of web-applications.

Recently, I upgraded my machine to Ubuntu Hardy Heron and the next day, I found that all the selenium tests started failling on my machine. On digging through the logs, I found the following information in the Selenium Server logs:

java.lang.RuntimeException: File was a script file, not a real executable: /usr/bin/firefox-bin

Before actually spotting this line, I was mis-led by other log messages; but I will not talk about them in this post.

The reason for the failing tests was that Selenium Server thought that the default executable found in the path (/usr/bin/firefox) was a script file and not an executable application for the browser. I am not sure why Selenium Server checks whether the path to the browser should not be a script.

The cause of the problem is that because of  Ubuntu Hardy Heron upgrade, my firefox also got upgraded from 2.x to 3.x. The firefox browser executable in 2.x is a binary file; whereas for firefox 3.x, it is a script (.sh) file. As a result of this change, the check done by  Selenium Server was failing.

I resolved this problem by providing explicit path to the Firefox 2 executable file in the java code. (I also tried providing explicit path to the Firefox 3 executable but that is no help).

So, the code for the Java Selenium test-case looks like this :

selenium = new DefaultSelenium("localhost", 4444, "*firefox /usr/lib/firefox/firefox-2-bin", url);

This is not a solution, if you want to test your app with Firefox 3. I haven’t figured out the solution for making it work with Firefox 3; but for the time being, I am happy with testing my application with Firefox 2.

If somebody has a solution for making it work with Firefox 3, please post the solution as a comment to the blog.

-Deepak

  • Share/Bookmark
This entry was posted on May 7th, 2008 at 6:02 pm and is filed under Java tools . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

16 Responses to “Web Testing using Selenium – fix for error “java.lang.NullPointerException: sessionId should not be null; has this session been started yet?””

  1. Vincnet says:

    I really expect the solution for the Firefox 3. don’t want to rollback to Firefox 2.

  2. kits says:

    i wasn’t successful making it work in F3, got it working in F2 though :-|

  3. cicada.tang says:

    I don’t know if you making it work with firfox 3?

  4. Robert Reiz says:

    dito.

  5. Neil says:

    Newest selenium-server.jar works with FF3.

  6. King Shooter says:

    Hi Friend,
    i got the same problem in Windows system. What should i do to solve it???

  7. Priya says:

    Hi Friend,
    While executing Selenium RC in Windows XP, system, i got the below exception. Please let me know how to resolve this problem?

    java.lang.NullPointerException: sessionId should not be null; has this session been started yet?

  8. Godwin says:

    Hi priya,

    Even i have encountered that same problem.I have just started with selenium.Can you please tel me how do u managed that error??

    Thanks,
    Godwind

  9. maosanch says:

    try selenium.start() after the constructor

  10. Matthias says:

    Hi guys! Have you figured out a solution for the sessionId being null problem?

    java.lang.NullPointerException: sessionId should not be null; has this session been started yet?

    I’m getting this every timie from my EasyB tests but not from regular tests. And yes, I’m calling the selenium.start() thingy after constructing the DefaultSelenium object.

  11. vas says:

    Guys,
    Here is the solution for this.

    Put at least 1 sec or 2 sec wait before start selenium.

    selenium = new DefaultSelenium(“localhost”, 4444, “firefox”, “http://www.google.co.uk/”);
    Thread.Sleep(2000); //This is for C#. Use specific language code for wait
    selenium.Start();

    After using the wait time I never got this problem. This is the work around and there is no fix from Selenium for this issue.

    Hope this helps lot.

  12. Gordopolis says:

    Hi, the Thread.Sleep(2000); line doesn’t resolve this for me?

    Can anyone clarify what versions of firefox conflict with selenium? I am using FireFox 3.6.10 and Selenium server 1.0.3.

    Thx

  13. Anes P.A says:

    Hi Friends,
    I am working in Fedora 12,php selenium RC. After starting the Selenium RC
    server running the Test not work it Give Error like:

    PHPUnit 3.3.17 by Sebastian Bergmann.

    E

    Time: 0 seconds

    There was 1 error:

    1) testTitle(WebTest)
    RuntimeException: Could not connect to the Selenium RC server.

    FAILURES!
    Tests: 1, Assertions: 0, Errors: 1.

    How it can Remedy, Waiting for a FAST reply
    reply me at : anes(dot)pa@gmail(dot)com.

    thankfully Anes P.A

  14. Paja says:

    Hello guys, I found out something interesting.

    Firstly start the selenium and than set all the parameters.

    selenium.start();
    selenium.setSpeed(CadrIIIwTestConfiguration.getSeleniumSpeed());
    selenium.setTimeout(10000);

    If you try to execute the code in a reversed order, you get the above mentioned sessionId error

    selenium.setSpeed(CadrIIIwTestConfiguration.getSeleniumSpeed());
    selenium.setTimeout(10000);
    selenium.start();

    Good luck.

  15. vineet says:

    Hi, i m getting following error on running selenium java code “sessionId should not be null; has this session been started yet?”

  16. teeth whitening scottsdale…

    [...]Web Testing using Selenium – fix for error “java.lang.NullPointerException: sessionId should not be null; has this session been started yet?” « Intelligrape Groovy & Grails Blogs[...]…

Leave a Reply