1

I have a simple automation script written in selenium webdriver. I need to execute this script through Jenkins. So I've configured the job in Jenkins and when tried to execute, I'm unable to open Firefox browser.

The console output is as follows:

Running TestSuite
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: cannot open display: :99
Failed tests: 
 NewTest.testEasy:25 » WebDriver Failed to connect to binary FirefoxBinary(/usr...

This is my code:

@Test
    public void testEasy() {
//          WebDriver driver = new FirefoxDriver();
        WebDriver driver = null;
        FirefoxBinary binary = new FirefoxBinary(new File("/usr/bin/firefox"));
        binary.setEnvironmentProperty("DISPLAY",System.getProperty("lmportal.xvfb.id",":99"));
        driver = new FirefoxDriver(binary,null);
        driver.get("https://www.google.co.in/?gfe_rd=cr&ei=drM-V8PiHPPI8AevjriQDA&gws_rd=ssl");
//          String title = driver.getTitle();
//          AssertJUnit.assertTrue(title.contains("Free Selenium Tutorials"));
//          System.out.println("TEST");
    }

2 Answers 2

12

Error: cannot open display: :99

When we run selenium scripts in jenkins they run in headless mode i.e. without any display. Hence they need some kind of virtual buffer for example Xvfb or alike.

In this case, script is looking for some virtual display on port :99, which is not running. If the jenkins box is linux try before running the selenium script.

Xvfb :99 &
export DISPLAY=:99
7
  • Thanks for your response. I executed the above command in terminal and executed the test case. The build is success, but no browser is opening.
    – Test admin
    Aug 30, 2016 at 5:57
  • For your reference I've added the code in my Question. Please refer that also.
    – Test admin
    Aug 30, 2016 at 5:58
  • wait.. as this is headless execution and you are running the command on terminal you would not see any browser coming up, the browser is in memory. But you can take screenshots of the required page. Aug 30, 2016 at 5:59
  • Okay.. I don't want headless execution.. I commented out the headless execution and executed the normal method.. when executed through eclipse the browser opened. But when executed through Jenkins, browser not opening. But the build is success.
    – Test admin
    Aug 30, 2016 at 6:01
  • In order to achieve this, you should have a physical display connected to the jenkins slave (machine where tests will be executed through jenkins). When you are running it through eclipse, i believe they are running on your local system and with display thats why you are able to see them executing. Aug 30, 2016 at 6:03
0

Actually I'm able to execute the script. But only browser is not visible. I'm ok with it. Also I tested with failing test script, and Jenkins returned with that error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.