Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the port that Webdriver Firefox connects to localhost?

I have a selenium webdriver test, converted to maven project, that I want to run via xvfb on Jenkins.

There is a problem with display selection, but I would like to try something else and change the port, for example.

This is the error I get:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.

Firefox console output:

Error: no display specified

Error: no display specified

And this is my code:

File ffExe = new File("/usr/bin/firefox");
FirefoxBinary ffox = new FirefoxBinary(ffExe);
ffox.setEnvironmentProperty("DISPLAY", ":21");
WebDriver driver = new FirefoxDriver(ffox, null);

So, how can I tell firefox to use another port and which one should I specify?

like image 213
Kaloyan Roussev Avatar asked Jul 29 '13 08:07

Kaloyan Roussev


2 Answers

The problem is not that it can't connect on that port, but rather the second part of the error, that there is no display specified in Jenkins. That's why setting the display for Firefox is probably not working.

Find out what your display settings are by typing env in the terminal and taking down the number assigned to your DISPLAY variable. For example DISPLAY:1.0.

Next you need to set the display variable in Hudson/Jenkins. Navigate to the Jenkins landing page then click Manage Jenkins>Manage Nodes>Master>Configure. Check the Environment variables check box, then set DISPLAY in the name box, and the value to something like our example :1.0.

Additionally you'll probably need to disable your xhost access controls using xhost + in the terminal.

like image 35
aajenkins Avatar answered Jan 02 '23 21:01

aajenkins


There is a System property -webdriver.firefox.port which could be the answer for yoru query. It is listed on the wiki - http://code.google.com/p/selenium/wiki/FirefoxDriver, but there is no documentaion provided for the same. You can try and let us know if it works :)

like image 85
Akbar Avatar answered Jan 02 '23 21:01

Akbar