java Selenium Webdriver - Debian Lenny 上的 FirefoxDriver 问题(错误无显示)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15877746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium Webdriver - Issue with FirefoxDriver on Debian Lenny (Error No display)
提问by blondeamon
I am using Selenium to test my website, it opens up a URL using Firefox, logins and does some stuff on the page and then logs out and shuts firefox. That all works great on Windows 7. The code starts with:
我正在使用 Selenium 测试我的网站,它使用 Firefox 打开一个 URL,登录并在页面上执行一些操作,然后注销并关闭 Firefox。这一切都在 Windows 7 上运行良好。代码开头为:
WebDriver driver = new FirefoxDriver();
driver.get(URL);
Now I deployed my jar in linux box that runs Debian lenny which has iceweasel on it. A cron job starts the program which throws the following error when trying to open firefox:
现在我将我的 jar 部署在运行 Debian lenny 的 linux 盒子中,它上面有 iceweasel。cron 作业启动程序,当尝试打开 Firefox 时抛出以下错误:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: Error: cannot open display: :0 Error: cannot open display: :0
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106) at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:110) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:179) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92) at auth.Authenticator.authenticate(Authenticator.java:15) at reader.ReaderThread.run(ReaderThread.java:67) org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows: Error: cannot open display: :0 Error: cannot open display: :0
Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: os.name: 'Linux', os.arch: 'i386', os.version: '2.6.26-2-686', java.version: '1.6.0_26' Driver info: driver.version: FirefoxDriver at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118) at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:110) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:179) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92) at auth.Authenticator.authenticate(Authenticator.java:15) at reader.ReaderThread.run(ReaderThread.java:67)
org.openqa.selenium.firefox.NotConnectedException:45000 毫秒后无法在端口 7055 上连接到主机 127.0.0.1。Firefox 控制台输出:错误:无法打开显示::0 错误:无法打开显示::0
在 org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106) 在 org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244) 在 org.openqa.selenium.remote.RemoteWebDriverr .(RemoteWebDriver.java:110) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183) 在 org.openqa.selenium .firefox.FirefoxDriver.(FirefoxDriver.java:179) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92) 在 auth.Authenticator.authenticate(Authenticator.java:15) 在 reader.ReaderThread.run( ReaderThread.java:67) org.openqa.selenium.WebDriverException: 无法连接到端口 7055 上的二进制 FirefoxBinary(/usr/bin/firefox);过程输出如下: 错误:
构建信息:版本:'unknown',修订:'unknown',时间:'unknown' 系统信息:os.name:'Linux',os.arch:'i386',os.version:'2.6.26-2- 686', java.version: '1.6.0_26' 驱动程序信息:driver.version: FirefoxDriver at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118) at org.openqa.selenium.firefox。 FirefoxDriver.startClient(FirefoxDriver.java:244) 在 org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:110) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190) 在 org.openqa .selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:179) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92) 在 auth.Authenticator.authenticate(Authenticator.java:15) 在 reader.ReaderThread.run(ReaderThread.java:67)
I have Xvfb running ok in the box and I have set variable DISPLAY to 0. I have searched around and none of the solutions (like setting the env variable) worked.
我的 Xvfb 在框中运行正常,并且我已将变量 DISPLAY 设置为 0。我四处搜索,但没有一个解决方案(如设置 env 变量)有效。
Isnt XVfb supposed to work as a non-graphical environment that the browser will launch into and do the necessary actions? What's stopping it from starting up?
XVfb 不应该作为浏览器将启动并执行必要操作的非图形环境工作吗?是什么阻止它启动?
I am using the latest Selenium version 2.31 and Firefox 3.0.6 Iceweasel.
我使用的是最新的 Selenium 2.31 版和 Firefox 3.0.6 Iceweasel。
Edit:Updated to Firefox 14 and still see the same issue. I even raised the timeout limit to 60 seconds.
编辑:已更新到 Firefox 14,但仍然看到相同的问题。我什至将超时限制提高到 60 秒。
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
SOLVED:By running it with the xvfb wrapper, xvfb-run like this:
已解决:通过使用 xvfb 包装器运行它, xvfb-run 像这样:
export DISPLAY=:0.0
xvfb-run --auto-servernum --server-num=0 nohup java - jar X.jar
采纳答案by blondeamon
Solved by doing this:
通过这样做解决:
export DISPLAY=:0.0 xvfb-run --auto-servernum --server-num=0 nohup java - jar X.jar
回答by Khyati Sehgal
I have seen the similar issue and this is coming only for firefox, for other browser everything was working fine, I tried on Chrome. Here is the solution for this 1. Check the version of FF, if it is latest, then go for a lesser version of FF. It is recommended for more stability. 2. And you should always try to take latest selenium binary from selenium website. For more details try this solution: http://khyatisehgal.wordpress.com/2014/09/09/at-org-openqa-selenium-firefox-internal-newprofileextensionconnection-startnewprofileextensionconnection-java106/
我见过类似的问题,这仅适用于 Firefox,对于其他浏览器,一切正常,我在 Chrome 上尝试过。解决方法如下: 1.检查FF的版本,如果是最新的,就换低版本的FF。建议使用更稳定。2. 你应该总是尝试从 selenium 网站获取最新的 selenium 二进制文件。有关更多详细信息,请尝试此解决方案:http: //khyatisehgal.wordpress.com/2014/09/09/at-org-openqa-selenium-firefox-internal-newprofileextensionconnection-startnewprofileextensionconnection-java106/
回答by buddy
Either try to update your webdriver or downgrade your firefox. this issue is related that selenium server cannot connect to your firefox.
尝试更新您的网络驱动程序或降级您的 Firefox。此问题与 selenium 服务器无法连接到您的 Firefox 相关。
回答by Venkat
This issue get resolved after upgraded to the latest Selenium jar.
升级到最新的 Selenium jar 后,此问题得到解决。