首页 文章

Webdriver在45000 ms后无法连接到端口7055上的主机127.0.0.1

提问于
浏览
132

我有盒子在哪里运行测试 . 看起来詹金斯会ssh并执行正在运行的特定作业中描述的命令 .

在这里,我试图运行我的Selenium Webdriver测试,但它告诉我在启动firefox时出错 . 最终的想法是完全在这个盒子上运行网络测试,并拍摄一些错误的截图 .

我正在使用selenium-java-2.25.jar,firefox 10,linux OS .

有趣的是,我可以手动ssh到框中,临时从框中的另一个用户复制魔术cookie(以获得X隧道),做一个 export DISPLAY=mydisplay:1.0 ,然后使用ant启动我的硒测试 . 这将带来firefox和测试就好了 .

这里有各种各样的线程似乎有完全相同的问题,我想我已经尝试了大部分 . 这就是我所做的:

  • 重新启动该框,使用VNC重新登录 .

  • 在运行selenium测试之前,在Jenkins中放置了一个bash脚本来运行 . bash脚本基本上只是 export DISPLAY=mydisplay:1.0 . 它还执行 xclock . 这可以工作,因为我可以看到在VNC中显示xclock .

  • iptables已被关闭

  • firefox正确位于/ usr / bin / firefox中

  • sshd_config显示X11Forwarding为true .

  • 据说降级firefox帮助了一些人,但我不想这样做 . 无论如何,Webdriver应该支持FF 10 .

但是,以上都没有解决问题 .

它似乎不存在localhost上的端口7055甚至存在:

netstat -an | grep 7055 - 什么都没打印

这是我的/ etc / hosts所说的:

1 127.0.0.1               localhost.localdomain localhost
  2 ::1             localhost6.localdomain6 localhost6

也许它与localhost有关:7055不存在?我不确定从哪里开始 . 仍然,为什么错误输出说当我指定 mydisplay:1.0 时它正在寻找 display: :0.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)

29 回答

  • 13

    我通过将我的Firefox降级到以前与Selenium-WebDriver配合得很好的旧版本来解决了这个问题 . 在我的情况下,我不得不降级到Firefox 18,这个版本与Selenium 2.27一起使用

    这是获取旧版本的Firefox的链接:https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/

  • 1

    我也有同样的问题但是在将firefox版本降级到35.0.1并且我的selenium版本是2.43后问题得到了解决

  • 0

    更新selenium jar,下载selenium 2.31.0

    这个问题已由硒人解决

    这是一个兼容性问题 .

    干杯

  • 0

    只需重启终端即可 . 终端没有其他任何东西被绞死 . 之后一切都会好起来的

  • 8

    我得到了同样的错误;我用过selenium-java 2.25.0和Firefox vresion 18.0.2;我已经将selenium-java的版本更改为2.30.0,现在可以正常工作了 .

  • 0

    获取FireFox 19的最新Selenium jar (2.30)

    你可以在这里下载最新的 jar (写作时为2.31):https://code.google.com/p/selenium/downloads/list

  • 4

    安装了Firefox Setup 18.0.exe它对我有用

  • 1

    我得到了相同的错误“selenium_Unable连接到端口7055上的主机127.0.0.1”解决方案:我已经使用selenium-java-2.48.2和Firefox版本43.0.1,现在它运行良好 .

  • 5

    我今天遇到了同样的问题 . 要修复我将firefox版本51降级到47并且它正在运行 .

    注意:我在虚拟盒中使用Linux Ubuntu Mate,主机是另一个Ubuntu Mate . 所有操作系统都是64位和Firefox也 .

  • 2

    我也遇到了同样的问题 . 每当我们或webdriver打开时,FF浏览器都会检查更新(如果有的话) . 在这种情况下,我将尝试在执行期间更新,然后即使因为您没有正确更新Selenium版本而正确更新,您也会收到错误 .

    导航到“http://docs.seleniumhq.org/download/”并下载最新版本 . 现在去检查一下,确实会解决问题 . :)

  • 0

    要解决此问题,请使用http://docs.seleniumhq.org/download/上提供的新jar文件 . 分别对应java,C#,php等... Firefox 27.0.1需要2.39.0的驱动版本 .

  • -1

    我也被这个错误困住了三天,最后想出来了 . 你可以查看我给出的答案here . 这是浏览器和selenium服务器兼容性问题 . 我希望这会有所帮助 . 您可以查看this link的浏览器兼容性

  • 1

    我有 Firefox 47Selenium 2.53 ,我得到了同样的错误 . 我的解决方案是将Firefox 47更改为 Firefox 46 ,问题解决了 .

  • 1

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

  • 91

    它发生在不同版本的ff上 . 我使用selenium-server-standalone-2.41.0.jar和selenium-java-2.41.0.zip使用最新的ff版本39,它显示相同的错误 .

    获取最新的服务器和客户端jar文件here以获得兼容性我分别使用服务器和客户端版本2.47.0和2.47.1 . 和繁荣!有效 .

  • 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("Контакт"));
     }
    

    Solution

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

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

    我认为这可能是一个显示问题 . 如果你的框中没有GUI,那么从selenium webdriver启动firefox就会出现这个错误 .

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

  • 0

    添加到知识库 . 我们在Bamboo上遇到了同样的问题 . 通过使用Bamboo上的环境属性解决了该问题 .

    DISPLAY=":1"
    

    在pom.xml或命令行中将值添加为系统属性不起作用 .

  • 0

    我有运行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)
    

    我已经按照建议和问题进行了整理 .

  • 1

    在选择使用Selenium进行测试之前,您需要检查浏览器兼容性:

    https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG

    这可能有助于回答上述问题 .

  • 0

    这个问题困扰了我很长时间,我看到一个有效的解决方案,如果Firefox是 use the upgraded firefox driver .

    • 如果您的 firefox upgrades are happening automatically 偶尔会遇到此问题 . 看起来Firefox的开发速度太快,或者他们不关心向后兼容性 .

    • 每当我在旧脚本上看到这个问题时,我会检查firefox版本是否已经发生变化 - 大部分时间都是如此 .

    • 然后我去maven repo for selenium firefox驱动程序repo - http://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver并下载最新版本 .

    • 或者更新我的pom.xml(如果使用maven),现在使用新版本的firefox驱动程序 - 2.40.0

    • 没有简单的方法可以避免此问题,除非您真正明确阻止来自firefox的自动更新(您可以在首选项中执行此操作(在Mac上) - 高级 - 更新 - 选择“检查更新,但让我选择是否安装它们“)

    • 如果脚本以自动模式运行,则可能需要禁用更新 . 然而,这可能会产生其他问题 . 由于大多数人/用户可能默认启用了firefox更新 . 因此,您的应用程序并未真正在任何更高版本上进行测试 .

  • 0

    如果我们的selenium脚本没有执行,请更新selenium jar . 目前我使用的是selenium-java-2.43.0-srcs

    现在它工作正常

  • 4

    这是因为旧版本 . 只需将浏览器更新到最新版本,并将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>
    
  • 0

    我有一个类似的问题 . 也许这个答案对你也有帮助 .

    看起来你有两个不同的错误:

    • Unable to connect to host 127.0.0.1 on port 7055

    • Error: no display specified

    Unable to connect 错误的原因是Selenium Server的版本不知道如何使用较新版本的Firefox . 您需要下载支持较新版本Firefox的较新版本的Selenium Server .

    出现 Error: no display specified 错误的原因是Firefox正在启动,但远程主机上没有运行X服务器(GUI) . 您可以使用X11转发在远程主机上运行Firefox,但将其显示在本地主机上 . 在Mac OS X上,您需要下载XQuartz才能使用X11转发 .

  • 14

    不知道你是否解决了这个问题,但我刚从另一方面解决了同样的问题 .

    看起来Selenium和Firefox很难相互交谈 - 我怀疑Firefox'发展'对多个版本的改变,因此并不总能保证向后和向前的兼容性,并且不兼容总是会产生相同的错误 .

    当我从FF 15移动到FF 16时,我的问题就出现了 . 在Ubuntu上运行,这种情况会随着其他升级而神奇地发生,但我相信这是一个关键变化 .

    从Selenium 2.24.1迁移到Selenium 2.25.0解决了这个问题

    由于selenium更改只是下载jar文件并运行它而不是旧文件,因此值得尝试将其作为快速简便的故障排除程序 - 如果它没有帮助,只需切换回来 . 在你的情况下,我不确定试用哪个版本的Selenium,但我认为2.24应该适用于FF 10 .

    我在过去发现的另一个问题是Firefox不会在Ubuntu上以root身份运行 . 如果Selenium作为服务运行,或者可能是从bash脚本或cron作业启动,则会发生这种情况 . 这可以解释为什么它适合你而不是詹金斯 .

  • 1

    解决方案 -

    1)升级你的Selenium服务器,即selenium jar "selenium-server-standalone-2.xx.x.JAR" TO "selenium-server-standalone-2.45.0.JAR"

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

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

    参考 - Download updated selenium libs & jar i.e. Version 2.45.0

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

  • 6

    在Windows上:检查Firefox的“位数” . Firefox 43.0.1 64位不适用于Selenium 2.50.0 . 适用于Firefox 43.0.1 32bit...

  • 0

    该脚本的问题是用于脚本的环境与用于测试的环境不同,因此设置环境变量对测试没有任何作用 .

    要正确设置变量,需要在Jenkins中设置它 . 转至管理Jenkins>管理节点>主服务器>配置 . 选中环境变量复选框,然后在名称框中输入DISPLAY,并将值设置为:1.0 .

    此外,您需要设置权限,尝试在终端中使用 xhost + 禁用您的xhost访问控制 .

相关问题