140
votes

I have box where I run tests. It seems like Jenkins would ssh in and execute commands described in the specific job that's running.

Here I am trying to run my Selenium Webdriver tests, but it tells me that I have errors in launching firefox. The end idea is to run the webtests on this box entirely, and also take some screenshots of errors.

I am using selenium-java-2.25.jar, firefox 10, linux OS.

The funny thing is that I can ssh in manually into the box, temporarily copy the magic cookie from another user on the box (to get an X tunnel), do an export DISPLAY=mydisplay:1.0, then launch my selenium tests using ant. And this will bring up firefox and the tests just fine.

There are various threads here that seem to have the exact same problem, and I think I've tried most of them. Here is what I've done:

  • Reboot the box, log back in with VNC.

  • Placed a bash script in Jenkins to run before running selenium tests. The bash script basically just does an export DISPLAY=mydisplay:1.0. It also executes xclock. This works as I can see xclock being displayed in the VNC.

  • iptables have been turned off

  • firefox is correctly located in /usr/bin/firefox

  • sshd_config shows having X11Forwarding as true.

  • Supposedly downgrading firefox helped some people, but I do not wish to do this. Webdriver should support FF 10 anyway.

However, none of the above solves the problem.

It doesn't seem like port 7055 on localhost even exists:

netstat -an | grep 7055 - Nothing prints

This is what my /etc/hosts says:

  1 127.0.0.1               localhost.localdomain localhost
  2 ::1             localhost6.localdomain6 localhost6

Perhaps it has something to do with localhost:7055 not existing? I am unsure where to go from here. still, why does the error output say it's looking for display: :0.0 when I've specified mydisplay:1.0?

And finally the error output I receive:

[testng] org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng] 
[testng] Error: cannot open display: :0.0
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng] 
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng] 
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng] 
[testng] Error: cannot open display: :0.0
[testng] 
[testng]    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:109)
[testng]    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:245)
[testng]    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:109)
[testng]    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:185)
[testng]    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:178)
[testng]    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:174)
[testng]    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
[testng]    at com.test.webtest.browser.BrowserFactory.createBrowser(BrowserFactory.java:24)
[testng]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[testng]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[testng]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[testng]    at java.lang.reflect.Method.invoke(Method.java:601)
29
I reproduced this problem under selenium 2.31.0Dima Star
I'm having this problem with Selenium 2.47.1 and I am not seeing the message that the firefox driver server started on port XXXX. Instead I get a blank window that opens and no control over the browser, assuming because the port didn't open to listen for wire protocol commands from the test.djangofan
It seems that combination of Selenium server 2.47.1 and Firefox 40 is OK, not working with Firefox 41 for me.Rostislav Matl
If you do not have GUI in your box and your are running your tests in the box using firefox, you get this error. I suggest you try with Xvfb in memory display driver. Or this could also be an issue of firefox version and selenium version compatibility.Prasanta Biswas

29 Answers

91
votes

Don't know if you resolved this problem, but I have just resolved the same issue from the other side.

It appears Selenium and Firefox have difficulty talking to each other - I suspect Firefox 'evolve' changes over a number of releases, so backward and forward compatibility are not always guaranteed, and incompatibility always seems to generate the same error.

My problem started when I moved from FF 15 to FF 16. Running on Ubuntu, this happens auto magically along with other upgrades but I believe this was the critical change.

The problem was resolved by moving from Selenium 2.24.1 to Selenium 2.25.0

As the selenium change is just download the jar file and run it instead of the old one,it's worth trying this as a quick and easy troubleshooter - if it doesn't help, just switch back. In your case, I'm not sure which version of Selenium to try, but I think 2.24 should work with FF 10.

Another issue I have found in the past is that Firefox would not run as root on Ubuntu. This happens if Selenium is running as a service, or possibly if it is fired up from a bash script or cron job. This may explain why it runs for you but not for Jenkins.

14
votes

I had a similar issue. Maybe this answer will help you as well.

It looks like you have two different errors going on:

  1. Unable to connect to host 127.0.0.1 on port 7055
  2. Error: no display specified

The reason for the Unable to connect error is that the version of Selenium Server does not know how to work with the newer version of Firefox. You need to download a newer version of the Selenium Server that supports the newer version of Firefox.

The reason for the Error: no display specified error is that Firefox is being launched, but there is no X server (GUI) running on the remote host. You can use X11 forwarding to run Firefox on the remote host, but display it on your local host. On Mac OS X, you will need to download XQuartz in order to use X11 forwarding.

13
votes

You need to check the browser compatibility before opting to test with Selenium:

https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG

This might help to answer the above question.

8
votes

Get the latest Selenium jars (2.30) for FireFox 19

You can download the latest jars (2.31 as of writing) here: https://code.google.com/p/selenium/downloads/list

6
votes

I resolved this issue by downgrading my Firefox to an older version that had previously worked well with Selenium-WebDriver. In my case, I had to downgrade back to Firefox 18 and this version worked with Selenium 2.27

Here is the link to get older versions of firefox: https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/

5
votes

This issue has haunted me for long time and I have seen one working solution in case of Firefox was to use the upgraded firefox driver.

  • If your firefox upgrades are happening automatically than you may face this problem once in a while. Looks like Firefox guys are developing too fast, or they do not care about backward compatibility.

  • Every time I see this issue on my old scripts I check if the firefox version has changed since - most of the times it is.

  • Then I go to maven repo for selenium firefox driver repo - http://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver and download the latest version.

  • or update my pom.xml (if maven is used) with new version of firefox driver right now its - 2.40.0

  • There is no easy way to avoid this issue unless you really explicitly block the automatied update from firefox (You can do this (On Mac) in preferences - Advanced - Update - Select "Check for updates, but let me choose whether to install them")

  • If your scripts are running on a automated mode then you may want to disable updates. However this may create other issues. Since most people/user may have firefox updates enabled by default. So your application is not really being tested on any later versions.

5
votes

I had Firefox 47 and Selenium 2.53, and i got the same error. My solution was change Firefox 47 to Firefox 46, the problem was solved.

4
votes

Update selenium jars, download selenium 2.31.0

This issue has been resolved by the selenium guys

This was a compatibility issue.

Cheers

3
votes

The problem with the script is that the environment used for the script is not the same as the one used for your tests, so setting the environment variables there does nothing for your tests.

To properly set the variable you need to set it in Jenkins. Go to Manage Jenkins>Manage Nodes>Master>Configure. Check the Environment variables check box, then enter DISPLAY in the name box, and set the value to :1.0.

Additionally you'll need to set permissions, try disabling your xhost access controls using xhost + in the terminal.

2
votes

I also faced the same problem. Whenever we or webdriver opens up the FF browser will check for the updates if any. In that case, i will try to update during the execution time and then you will be getting the error even if it is updated properly just because you have not update the Selenium version appropriately.

Navigate to "http://docs.seleniumhq.org/download/" and download the latest version. Now go and check, the problem would be resolved, indeed. :)

1
votes

I got the same error; I've used selenium-java version 2.25.0 and Firefox vresion 18.0.2; I've changed the version of selenium-java to 2.30.0 and now works.

1
votes

For solve this issue, use new jar files available on http://docs.seleniumhq.org/download/. As respective to java, C#, php etc...Firefox 27.0.1 require 2.39.0 of driver version.

1
votes

Just install Xvnc Plugin in Jenkins. The problem should be solved.

1
votes

I got the same error "selenium_Unable to connect to host 127.0.0.1 on port 7055" Solution : I've used selenium-java-2.48.2 with Firefox version 43.0.1 and now its working well.

1
votes

Me too had the same problem but issue is resolved after downgrading firefox version to 35.0.1 and my selenium version is 2.43

1
votes

I had the exact same problem running docker but I found the solution in the log preceding the error you've mentioned.

selenium_1  | 2016-11-11 11:19:34,498 DEBG 'xvfb' stderr output:
selenium_1  | (EE)
selenium_1  | Fatal server error:
selenium_1  | (EE) Server is already active for display 99
selenium_1  |   If this server is no longer running, remove /tmp/.X99-lock
selenium_1  |   and start again.
selenium_1  | (EE)

I've followed the advice and problem has been sorted out.

0
votes

This is how it's behaved when I used static property of IWebDriver and call it from multiple test methods.

public class LanguageMenu
{
    private static IWebDriver drv;

    static LanguageMenu()
    {
       drv = Driver.Instance;
    }
    ...

    public static void English()
    {
        drv.FindElement(By.Id("mvc_lang_en"));
        el.Click();
    }

    public static void Rusian()
    {
        ...
    }

    ...
}

Like

 [TestMethod]
 public void Language_SwitchTo_English()
 {
     LanguageMenu.English();
     Assert.IsTrue(ContactPage.IsAt("Contact"));
 }

 [TestMethod]
 public void Language_SwitchTo_Rusian()
 {
     LanguageMenu.English();
     Assert.IsTrue(ContactPage.IsAt("Контакт"));
 }

Solution

For each calling test methods create new instance of Driver

 private static void English()
 {
            var drv = Driver.Instance;
            var el = drv.FindElement(By.Id("mvc_lang_en"));
            el.Click();
 }
0
votes

Update selenium jars if our selenium script is not executing. Currently i am using selenium-java-2.43.0-srcs

Now it is working fine

0
votes

It happens on different versions of ff. I'm using latest ff version 39 by using selenium-server-standalone-2.41.0.jar and selenium-java-2.41.0.zip which shows same error.

Get the latest server and client jar files here for the compatibility i used server and client versions 2.47.0 and 2.47.1 respectively. And Boom! It worked.

0
votes

This happens because of old versions. Just update the browser to latest version and update the selenium webdriver package to latest version.

0
votes

Just Restart the terminal. Terminal is hanged nothing else. Everything will work fine after that

0
votes

Adding to the knowledge base. We had the same issue on Bamboo. The problem was resolved by using the Environmental Properties on Bamboo.

DISPLAY=":1"

Adding the value as system properties in the pom.xml, or the command line did not work.

0
votes

On Windows: Check as well the "bitness" of your Firefox. Firefox 43.0.1 64bit does not work with Selenium 2.50.0. Working well with Firefox 43.0.1 32bit ...

0
votes

I too was stuck at this error for three days and finally figured it out.You can view the answer I have given here .This is browser and selenium server compatibility issue. I hope this helps.You can check browser compatibility from this link

0
votes

I had the same problem today. To fix I downgraded firefox version 51 to 47 and it's working.

Note: I'm using a Linux Ubuntu Mate, in a Virtual Box, with host being another Ubuntu Mate. All OS are 64 bits and firefox also.

0
votes

Installed Firefox Setup 18.0.exe it works for me

0
votes

I had the same issue with firefox 38.

After using following version dependencies, I could resolve the issue.

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.53.0</version>
    </dependency> 
0
votes

I think this could be a problem of display. If you do not have GUI in the box, then launching firefox from selenium webdriver would give this error.

To resolve this, first install Xvfb [yum install Xvfb -y]( a virtual display driver) in the box. Then run your test from jenkins with xvfv-run -a -d <your test execution command>. This will launch the browser in a virtual display buffer. Also it is capable of getting screenshots using selenium webdriver.

-1
votes

Solution -

1) Upgrade your Selenium Server i.e. selenium jar "selenium-server-standalone-2.xx.x.JAR" TO "selenium-server-standalone-2.45.0.JAR"

2) Upgrade your Selenium Client Driver i.e. selenium libs folder "selenium-java-2.xx.x" TO "selenium-java-2.45.0"

3) Check and Install compatible Firefox version

Refer - Download updated selenium libs & jar i.e. Version 2.45.0

This will RESOLVE your problem.. Cheers !!