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个回答

1

对我来说,它也适用于Firefox 29.0和selenium driver 2.39.0。(之前我在lubuntu 14.0.4上遇到了同样的问题) - Huluvu424242

1

只需在Jenkins中安装Xvnc插件即可解决问题。


1

我也遇到了同样的问题,但是将Firefox版本降级至35.0.1后问题得到解决,我的Selenium版本是2.43。


1

我遇到了相同的错误 "selenium_Unable to connect to host 127.0.0.1 on port 7055" 解决方法:我使用的是selenium-java-2.48.2和Firefox版本43.0.1,现在它可以正常工作。


1

我遇到了同样的错误;我使用的是selenium-java版本2.25.0和Firefox版本18.0.2;我将selenium-java版本更改为2.30.0,现在可以正常工作。


1

我在运行Docker时遇到了完全相同的问题,但是我在你提到的错误之前的日志中找到了解决方案。

selenium_1  | 2016-11-11 11:19:34,498 DEBG 'xvfb' stderr output:
selenium_1  | (EE)
selenium_1  | Fatal server error:
selenium_1  | (EE) Server is already active for display 99
selenium_1  |   If this server is no longer running, remove /tmp/.X99-lock
selenium_1  |   and start again.
selenium_1  | (EE)

我按照建议去做了,问题已经解决了。


0

增加知识库。我们在Bamboo上遇到了同样的问题。通过使用Bamboo上的环境属性,问题得以解决。

DISPLAY=":1"

将值作为系统属性添加到pom.xml或命令行中均未生效。


0

当我使用IWebDriver的静态属性并从多个测试方法中调用它时,它的行为就是这样的。

public class LanguageMenu
{
    private static IWebDriver drv;

    static LanguageMenu()
    {
       drv = Driver.Instance;
    }
    ...

    public static void English()
    {
        drv.FindElement(By.Id("mvc_lang_en"));
        el.Click();
    }

    public static void Rusian()
    {
        ...
    }

    ...
}

喜欢

 [TestMethod]
 public void Language_SwitchTo_English()
 {
     LanguageMenu.English();
     Assert.IsTrue(ContactPage.IsAt("Contact"));
 }

 [TestMethod]
 public void Language_SwitchTo_Rusian()
 {
     LanguageMenu.English();
     Assert.IsTrue(ContactPage.IsAt("Контакт"));
 }

解决方案

对于每个调用测试方法,创建一个新的Driver实例

 private static void English()
 {
            var drv = Driver.Instance;
            var el = drv.FindElement(By.Id("mvc_lang_en"));
            el.Click();
 }

0

只需重新启动终端。 终端卡住了,没有其他问题。 之后一切都会正常工作。


0

这个问题在不同版本的ff上发生。我使用的是最新版本39的ff,通过selenium-server-standalone-2.41.0.jar和selenium-java-2.41.0.zip,显示相同的错误。

获取最新的服务器和客户端jar文件在此处以获得兼容性,我分别使用了服务器和客户端版本2.47.0和2.47.1。结果出奇的顺利。


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