在这里,我试图运行我的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)