问题描述
我有箱子在哪里运行测试。詹金斯似乎会在执行特定作业中描述的命令时执行命令。这里我试图运行我的Selenium Webdriver测试,但是它告诉我在启动firefox时出现错误。最终的想法是完全在这个盒子上运行网络测试,并且也截取一些错误的截图。
我使用的是selenium-java-2.25.jar,firefox 10,linux操作系统。
是我可以手动ssh进入框中,临时复制魔术cookie从另一个用户(获得X隧道),做一个导出DISPLAY = mydisplay:1.0
,然后启动我的硒测试使用蚂蚁。这将带来Firefox和测试就好。
这里有各种线程似乎有完全相同的问题,我想我已经尝试了大部分他们。这是我所做的:
-
重新启动这个盒子,用VNC登录。在运行selenium测试之前,在Jenkins中放置一个bash脚本来运行。 bash脚本基本上只是执行
export DISPLAY = mydisplay:1.0
。它还执行xclock
。这工作正如我可以看到xclock显示在VNC中。 iptables已关闭 firefox正确位于/ usr / bin / firefox -
sshd_config显示X11Forwarding为true。 人,但我不希望这样做。 Webdriver应该支持FF 10。
但是,以上都没有解决这个问题。
$ b
似乎并不像localhost上的端口7055一样存在:
netstat -an | grep 7055
- Nothing print
这就是我的/ etc / hosts所说的:
1 127.0.0.1 localhost.localdomain localhost
2 :: 1 localhost6.localdomain6 localhost6
也许它与localhost:7055不存在有关系?我不确定该从哪里出发。仍然,为什么错误输出说当我指定 mydisplay:1.0
时,它正在寻找 display::0.0
?
最后我收到的错误输出:
$ p $ [testng] org.openqa.selenium.firefox.NotConnectedException:无法在45000 ms后连接到端口7055上的主机127.0.0.1。 Firefox控制台输出:
[testng] Xlib:连接到服务器拒绝的:0.0
[testng] Xlib:没有指定协议
[testng]
[testng]无法打开显示:0.0
[testng] Xlib:连接到:0.0服务器拒绝
[testng] Xlib:没有指定协议
[testng]
[testng] Xlib:连接到服务器拒绝的:0.0
[testng] Xlib:没有指定协议
[testng]
[testng] Xlib:服务器拒绝连接:0.0
[testng] Xlib:没有指定协议
[testng]
[testng]错误:无法打开显示:: 0.0
[testng]
[testng] at org.openqa .selenium.firefox.internal.NewProfileExtensionConnection.start($ New $)
[testng]在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。 < 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和Firefox ha很难彼此交谈 - 我怀疑Firefox的发展会改变一些版本,所以后向兼容性并不总是保证,不兼容总是会产生同样的错误。
当我从FF 15移到FF 16时,我的问题就开始了。在Ubuntu上运行时,这种情况会随着其他升级而神奇地发生,但是我相信这是一个关键的变化。这个问题已经从Selenium 2.24.1迁移到Selenium 2.25.0了解了。因为硒的变化只是下载jar文件并运行它而不是旧的,值得试试这个作为一个快速和简单的疑难解答 - 如果没有帮助,只需切换回来。在你的情况下,我不确定哪个版本的Selenium可以尝试,但是我认为2.24应该和FF 10一起工作。
过去我发现的另一个问题是Firefox不会在Ubuntu上以root身份运行。如果Selenium作为服务运行,或者可能从bash脚本或cron作业启动,则会发生这种情况。这也许可以解释为什么它为你运行,但不是为詹金斯运行。
I have box where I run tests. It seems like Jenkins would ssh in and execute commands described in the specific job that's running.
Here I am trying to run my Selenium Webdriver tests, but it tells me that I have errors in launching firefox. The end idea is to run the webtests on this box entirely, and also take some screenshots of errors.
I am using selenium-java-2.25.jar, firefox 10, linux OS.
The funny thing is that I can ssh in manually into the box, temporarily copy the magic cookie from another user on the box (to get an X tunnel), do an export DISPLAY=mydisplay:1.0
, then launch my selenium tests using ant. And this will bring up firefox and the tests just fine.
There are various threads here that seem to have the exact same problem, and I think I've tried most of them. Here is what I've done:
Reboot the box, log back in with VNC.
Placed a bash script in Jenkins to run before running selenium tests. The bash script basically just does an
export DISPLAY=mydisplay:1.0
. It also executesxclock
. This works as I can see xclock being displayed in the VNC.iptables have been turned off
firefox is correctly located in /usr/bin/firefox
sshd_config shows having X11Forwarding as true.
Supposedly downgrading firefox helped some people, but I do not wish to do this. Webdriver should support FF 10 anyway.
However, none of the above solves the problem.
It doesn't seem like port 7055 on localhost even exists:
netstat -an | grep 7055
- Nothing prints
This is what my /etc/hosts says:
1 127.0.0.1 localhost.localdomain localhost
2 ::1 localhost6.localdomain6 localhost6
Perhaps it has something to do with localhost:7055 not existing? I am unsure where to go from here. still, why does the error output say it's looking for display: :0.0
when I've specified mydisplay:1.0
?
And finally the error output I receive:
[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)
Don't know if you resolved this problem, but I have just resolved the same issue from the other side.
It appears Selenium and Firefox have difficulty talking to each other - I suspect Firefox 'evolve' changes over a number of releases, so backward and forward compatibility are not always guaranteed, and incompatibility always seems to generate the same error.
My problem started when I moved from FF 15 to FF 16. Running on Ubuntu, this happens auto magically along with other upgrades but I believe this was the critical change.
The problem was resolved by moving from Selenium 2.24.1 to Selenium 2.25.0
As the selenium change is just download the jar file and run it instead of the old one,it's worth trying this as a quick and easy troubleshooter - if it doesn't help, just switch back. In your case, I'm not sure which version of Selenium to try, but I think 2.24 should work with FF 10.
Another issue I have found in the past is that Firefox would not run as root on Ubuntu. This happens if Selenium is running as a service, or possibly if it is fired up from a bash script or cron job. This may explain why it runs for you but not for Jenkins.
这篇关于Webdriver无法在45000 ms后连接到端口7055上的主机127.0.0.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!