techjourneyman
techjourneyman

Reputation: 1813

Error running Selenium UI tests via Firefox on Jenkins

I am trying to run UI tests using FireFox Webdriver via Jenkins. I am using xvfb to emulate the browser, since the build box does not have a display.

I am running into the following error:

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. (user: 'UnknownUser-0', output: '1423245467418')
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: os.name: 'Linux', os.arch: 'amd64', java.version: '1.7.0_25'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
    at library.util.BrowserFactory.getFirefoxWebDriver(BrowserFactory.java:126)
    at library.util.BrowserFactory.getWebDriver(BrowserFactory.java:70) 
    at TESTS.myTestPkg.TestSomething.<init>(TestSomething.java:15)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)  
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 [/127.0.0.1] failed: Connection refused
    at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
    at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:204)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:173)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
    at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:72)
    at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:117)

Xvfb is starting as below before the build starts, and this is configured using the xvfb plug in for Jenkins:

Xvfb starting$ /usr/bin//Xvfb :10 -screen 0 1024x768x24 -fbdir /srv/jenkins/xvfb-2015-02-06_12-57-37-3245666068187787922.fbdir

I ensured that Firefox is in the PATH.

Could someone please tell me how to fix it?

Upvotes: 0

Views: 610

Answers (1)

Sachin Gandhi
Sachin Gandhi

Reputation: 11

First fix your Firefox version and selenium version match by testing it locally. If you are running job through Jenkins and in the logs you are getting error Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: Error: cannot open display: :0

To resolve look below steps:

1) Firefox will launch only if you have Xvfb running, example: Xvfb :15 -screen 0 1024x768x16 so check this first, this check you could include into job by adding ps -ef into pre-steps (shell execution) of job. Xvfb :15 -screen 0 1024x768x16 & you could run into your host/node where test has to be launched in a headless mode.

2) Even if you would have define explicitly the DISPLAY value but you have still error then the best method is to inject as a environmental value in Jenkin job itself. Under Build environment >> Inject env variables >> Properties content >> DISPLAY=:15 (Display you could have as per your choice but same should be running in xvfb)

!! Run your job, should have been fix.

Upvotes: 0

Related Questions