我正在尝试在java中运行无头webdriver测试。当我尝试使用:1显示运行webdriver测试时,它会给我错误
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
(process:30300): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: cannot open display: :1
(process:30308): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: cannot open display: :1
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at timnow.main(timnow.java:25)
Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:
(process:30300): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: cannot open display: :1
(process:30308): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: cannot open display: :1
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'santhu-personal', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.8.0-35-generic', java.version: '1.7.0_51'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:130)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at timnow.main(timnow.java:25)
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
(process:30300): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: cannot open display: :1
(process:30308): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: cannot open display: :1
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
... 6 more
以下是获取wd实例的代码
String Xport = System.getProperty("lmportal.xvfb.id", ":1");
System.out.println(Xport);
final File firefoxPath = new File(System.getProperty("lmportal.deploy.firefox.path",
"/usr/bin/firefox"));
FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
FirefoxDriver wd;
wd = new FirefoxDriver(firefoxBinary, null);
虽然我可以用xvfb运行测试。我对这个问题做了一些研究。有些人似乎已经解决了升级webdriver的问题,但我使用的是最新的webdriver jar,即2.41.0 with firefox version 26.0
答案 0 :(得分:1)
尝试像一个过程一样运行它:
xvfb-run -a java -jar your_jar.jar
答案 1 :(得分:0)
我犯了不运行xvfb的错误,一旦我将其作为单独的进程启动,它就开始工作了。