我有用来运行测试的盒子。看起来Jenkins会ssh进入并执行正在运行的特定作业中描述的命令。
这里我正在尝试运行Selenium Webdriver测试,但它告诉我在启动firefox时出现错误。最终的想法是完全在这个盒子上运行网络测试,并截取一些错误的屏幕截图。
我使用selenium-java-2.25.jar,Firefox10,linux操作系统。
有趣的是,我可以手动ssh到机器中,临时复制机器上另一个用户的魔力cookie (以获得X隧道),执行export DISPLAY=mydisplay:1.0
,然后使用ant启动我的selenium测试。这将调出firefox和测试。
这里有不同的线程似乎有完全相同的问题,我想我已经尝试了大多数。下面是我所做的:
export DISPLAY=mydisplay:1.0
。它还执行xclock
。这是可行的,因为我可以看到在VNC中显示了xclock。true.然而,上述方法都不能解决问题。
本地主机上的端口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)
发布于 2012-10-24 20:23:41
不知道你是否解决了这个问题,但我刚刚从另一个角度解决了同样的问题。
Selenium和Firefox似乎很难相互交流--我怀疑Firefox在许多版本中都在“进化”变化,所以向后和向前的兼容性并不总是有保证的,而且不兼容似乎总是会产生相同的错误。
当我从FF 15升级到FF 16时,我的问题就开始了。在Ubuntu上运行,随着其他的升级,这种情况会自动发生,但我相信这是关键的变化。
通过从Selenium 2.24.1迁移到Selenium 2.25.0解决了这个问题
由于selenium的更改只是下载jar文件并运行它,而不是运行旧的jar文件,因此值得尝试将其作为快速简单的故障排除程序-如果它不起作用,只需切换回来。在您的例子中,我不确定应该尝试哪个版本的Selenium,但我认为2.24应该可以与FF 10一起使用。
我过去发现的另一个问题是Firefox不能在Ubuntu上以root用户身份运行。如果Selenium是作为服务运行的,或者可能是从bash脚本或cron作业启动的,就会发生这种情况。这可能解释了为什么它为你运行,而不是为Jenkins运行。
发布于 2014-12-31 12:20:36
我也遇到过类似的问题。也许这个答案也会对你有所帮助。
看起来你有两个不同的错误:
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服务器。您可以使用X11转发在远程主机上运行Firefox,但在您的本地主机上显示它。在Mac上,为了使用X11转发,你需要下载XQuartz。
发布于 2013-05-07 14:26:49
在选择使用Selenium进行测试之前,您需要检查浏览器兼容性:
https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG
这可能有助于回答上述问题。
https://stackoverflow.com/questions/12588082
复制相似问题