Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have a 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 web tests 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:

  1. Reboot the box, log back in with VNC.
  2. 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.
  3. iptables have been turned off
  4. firefox is correctly located in /usr/bin/firefox
  5. sshd_config shows having X11Forwarding as true.
  6. 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 say:

 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)

1 Answer

0 votes
by (62.9k points)

This may be due to inconsistency between the Firefox Browser and Selenium Version installed in your system. If you are using the Latest Version of Firefox Browser, then make sure that you have the Latest Gecko Driver and the Latest Version of Selenium Jars added to your Java Project.

You can download the Latest Versions from the below links:

(i) Mozilla Firefox: https://www.mozilla.org/en-US/firefox/new/

(ii) Gecko Driver: https://github.com/mozilla/geckodriver/releases

(iii) Selenium Jars: https://goo.gl/LtVMqu

Hope this helps!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...