在Jenkins上通过Firefox运行Selenium UI测试时出错

时间:2015-02-06 19:05:12

标签: firefox selenium jenkins selenium-webdriver xvfb

我正在尝试通过Jenkins使用FireFox Webdriver运行UI测试。我使用xvfb模拟浏览器,因为构建框没有显示。

我遇到了以下错误:

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在构建开始之前如下所示开始,这是使用Jenkins的xvfb插件配置的:

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

我确保Firefox在PATH中。

有人可以告诉我如何解决它吗?

1 个答案:

答案 0 :(得分:0)

首先通过在本地测试来修复Firefox版本和selenium版本匹配。如果您正在通过Jenkins运行作业并且在日志中出现错误,则无法在45000 ms后在端口7055上连接到主机127.0.0.1。 Firefox控制台输出:错误:无法打开显示:: 0

要解决以下步骤:

1)只有在Xvfb运行时才会启动Firefox 示例:Xvfb:15-screen 0 1024x768x16所以首先检查一下,这个检查可以通过将ps -ef添加到作业的预执行(shell执行)中来包含到作业中。 Xvfb:15-screen 0 1024x768x16&amp;您可能会遇到必须以无头模式启动测试的主机/节点。

2)即使您明确定义了DISPLAY值但仍有错误,那么最好的方法是在Jenkin作业本身注入环境值。在构建环境&gt;&gt;下注入env变量&gt;&gt;属性内容&gt;&gt; DISPLAY =:15(您可以根据自己的选择显示,但同样应该在xvfb中运行)

!!运行你的工作,应该已经解决了。