Webdriver在45000毫秒后无法连接到127.0.0.1端口7055的主机。

140
我有一个盒子,在里面运行测试。似乎Jenkins会通过SSH登录并执行正在运行的特定作业中描述的命令。
在这里,我试图运行我的Selenium Webdriver测试,但它告诉我在启动Firefox时存在错误。最终的想法是完全在这个盒子上运行Web测试,并且拍摄一些错误的截屏。
我正在使用selenium-java-2.25.jar、firefox 10和Linux操作系统。
有趣的是,我可以手动ssh到盒子中,在另一个用户的魔术cookie上暂时复制cookie(以获得X隧道),然后使用ant启动我的Selenium测试。export DISPLAY=mydisplay:1.0,这将打开Firefox并正常运行测试。
这里有一些帖子似乎有完全相同的问题,而我认为我已经尝试过大部分。以下是我所做的:
- 重启盒子,使用VNC重新登录。 - 在Jenkins中放置一个bash脚本,在运行Selenium测试之前运行该脚本。bash脚本基本上只是执行export DISPLAY=mydisplay:1.0,并执行xclock。这有效,因为我可以在VNC中看到xclock被显示出来。 - iptables已被关闭。 - firefox正确地位于/usr/bin/firefox。 - sshd_config显示X11Forwarding为true。 - 据说降级firefox对一些人有帮助,但我不想这样做。Webdriver应该支持FF 10。
但是,以上所有方法都没有解决问题。
似乎本地主机上甚至不存在7055端口: netstat -an | grep 7055 - 未输出任何内容
这是我的/etc/hosts文件内容:
  1 127.0.0.1               localhost.localdomain localhost
  2 ::1             localhost6.localdomain6 localhost6

也许这与localhost:7055不存在有关?我不确定该从哪里开始。但是,为什么错误输出会说正在寻找display::0.0,而我已经指定了mydisplay:1.0呢?

最后,我收到的错误输出如下:

[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)

我在selenium 2.31.0下重现了这个问题。 - Dima Star
我正在使用Selenium 2.47.1遇到问题,没有看到Firefox驱动程序服务器已启动在端口XXXX上的消息。 相反,我打开了一个空白窗口,并且无法控制浏览器,这可能是因为端口没有打开以便从测试接收协议命令。 - djangofan
看起来 Selenium 服务器 2.47.1 和 Firefox 40 的组合是可以的,但无法在 Firefox 41 上工作。 - Rostislav Matl
如果您的计算机中没有GUI,并且正在使用Firefox在计算机中运行测试,则会出现此错误。我建议您尝试使用Xvfb内存显示驱动程序。或者这也可能是Firefox版本和Selenium版本兼容性的问题。 - Prasanta Biswas
29个回答

0

如果我们的Selenium脚本无法执行,请更新Selenium Jars。 目前我正在使用selenium-java-2.43.0-srcs

现在它可以正常工作。


0
今天我遇到了同样的问题。 为了解决这个问题,我将Firefox版本从51降级到47,现在它可以正常工作了。
注意:我正在使用Linux Ubuntu Mate,在Virtual Box中运行,主机是另一个Ubuntu Mate。所有操作系统都是64位的,Firefox也是。

0

我安装了Firefox Setup 18.0.exe,它对我有效。


0
这是由于旧版本的原因发生的。只需将浏览器更新到最新版本并将selenium webdriver包更新到最新版本即可。

0

我也被这个错误困扰了三天,最后找到了解决方法。您可以查看我在这里给出的答案。这是浏览器和Selenium服务器兼容性问题。希望这可以帮助您。您可以从这个链接检查浏览器兼容性。


0
在Windows上: 还要检查Firefox的“位数”。Firefox 43.0.1 64位版本不兼容Selenium 2.50.0。 Firefox 43.0.1 32位版本可以正常工作...

0

我认为这可能是一个显示问题。如果您的机器上没有GUI,则从selenium webdriver启动firefox会出现此错误。

要解决此问题,请首先在该机器上安装Xvfb(一种虚拟显示驱动程序)[yum install Xvfb -y]。然后使用xvfv-run -a -d <your test execution command>在Jenkins中运行您的测试。这将在虚拟显示缓冲区中启动浏览器。此外,它还能够使用selenium webdriver获取屏幕截图。


0

我在使用Firefox 38时遇到了同样的问题。

在使用以下版本依赖关系后,我解决了这个问题。

    <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> 

-1

解决方案 -

1)升级您的Selenium服务器,即selenium jar“selenium-server-standalone-2.xx.x.JAR”到“selenium-server-standalone-2.45.0.JAR”

2)升级您的Selenium客户端驱动程序,即selenium libs文件夹“selenium-java-2.xx.x”到“selenium-java-2.45.0”

3)检查并安装兼容的Firefox版本

参考 - 下载更新的selenium libs和jar,即版本2.45.0

这将解决您的问题...干杯!!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接