Could not start Selenium session: in Junit 3.8.2 test and selenium 3.4 on linux

401 views Asked by At

My environment:

linux ubuntu

selenium-html-runner-3.4.0.jar

selenium-java-3.4.0

selenium-server-standalone-3.4.0.jar

to build I do:

 javac -cp "/usr/share/java/junit.jar:/home/me/ushare/hobo/selenium/selenium-html-runner-3.4.0.jar:." TestHobo2.java

to run selenium-server:

java -jar selenium-server-standalone-3.4.0.jar

to run the test I do:

java junit.textui.TestRunner TestHobo2

and I get:

java.lang.RuntimeException: Could not start Selenium session:

at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:114) at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:139) at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:108) at com.thoughtworks.selenium.SeleneseTestCase.setUp(SeleneseTestCase.java:113) at TestHobo2.setUp(TestHobo2.java:10) at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:289) Caused by: com.thoughtworks.selenium.SeleniumException:

at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:111) at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:105) at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:277) at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:239) at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:105) ... 15 more

Here is my test case:

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

public class TestHobo2 extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("http://www.example.com/", "*chrome");
    }
    public void testGetLink() throws Exception {
        selenium.type("name=p_loc", "groove");
        selenium.click("css=input[type=\"Submit\"]");
        selenium.waitForPageToLoad("30000");
    }
}

Edit 2017/07/20 More info:

I am using Firefox version 52.0.2 (64-bit).

Should I be getting the following after the build?

Note: TestHobod2.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

geckodriver -v

1500554646753 geckodriver INFO geckodriver 0.18.0

1500554646753 webdriver::httpapi DEBUG Creating routes

1500554646764 geckodriver ERROR Address in use (os error 98)

2

There are 2 answers

3
Martin On BEST ANSWER

Are you sure that you have properly defined on which ip address and port is selenium running? Run your selenium server and put http://127.0.0.1:4444/wd/hub/ link into your browser. Try to create new session manually (click on create session and select browser, see image below), new browser blank window should appear. If this is working correctly than selenium server is ok. Then there can be problem with connection between server and your runner.
screen of selenium hub with create session option
Do you have correctly setup selenium driver? For example I'm using

new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"),DesiredCapabilities.firefox())

EDIT1: Show example of setUp method which create instance of RemoteDriver, create new browser session and fill url.

WebDriver driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), DesiredCapabilities.firefox());
driver.manage().window().maximize()//maximaze window as possible
driver.get("www.google.com"); //navigate to google, i.e. fill url into opened session
3
Krishnan Mahadevan On

Looking at the codebase, and trying to map your shared test code, seems to suggest that you will end up invoking a Firefox browser. The underlying implementation in Selenium has ensured that this will cause your test code to resort to perhaps using firefox.

Can you please ensure that you have made geckodriver downloaded and made available in your PATH variable ?

If that doesn't fix the problem (which could mostly be due to mismatch between the firefox version that you have in your desktop and the geckodriver version ), you can try switching to using Google Chrome.

You can switch to google chrome by

Changing : setUp("http://www.example.com/", "*chrome"); To : setUp("http://www.example.com/", "*googlechrome");

And see if that spins off the browser (For google chrome you would need to ensure you have chromedriver downloaded and made available in your local machine)