ubuntu cli 中的 Firefox GLib-CRITICAL 错误

Firefox in ubuntu cli GLib-CRITICAL error

我已经在我的 ubuntu 服务器上安装了 Firefox,因此我可以通过链接到 bitbucket 的 jenkins 运行 selenium 测试。

Jenkins 告诉我它无法访问 firefox 所以我用

安装了它
sudo apt-get install firefox

这安装了 firefox 版本 38。测试继续给出这样的错误

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host    
127.0.0.1 on port 7055 after 45000 ms. Firefox console output:

(process:28482): GLib-CRITICAL **: g_slice_set_config: assertion 
'sys_page_size == 0' failed

Error: no display specified

(process:28489): GLib-CRITICAL **: g_slice_set_config: assertion 
'sys_page_size == 0' failed

Error: no display specified

当我检查版本时出现此错误。我已经完全删除 firefox 并从 tar 文件安装到版本 35,因为我读到这可以解决问题。

它没有修复它,错误返回完全相同但版本已更改为 35。

这是 Jenkins 正在 运行ning

的主要脚本
public class Test {
protected WebDriver driver;

@Before  
public void setUp(){        
driver = new FirefoxDriver(); 
driver.get("http://www.google.com");

} //End Before

@Test

public void testGoogleSearch() { 

   // Find the text input element by its name          
WebElement element =  driver.findElement(By.name("q"));
   // Enter something to search for          
element.sendKeys("Selenium testing tools cookbook");
   // Now submit the form. WebDriver will find             
//the form for us from the element            
element.submit();

System.out.println("You have just logged into the  google6 website");

} //End of google search

@After   
public void tearDown() throws Exception {       
//Close the browser

driver.quit();
}
}//end

我不认为脚本是问题所在,但我想我会尝试构建一个完整的画面。

非常感谢任何修复此 firefox 错误的帮助。谢谢

更新 1

我用的是Maven,selenium的版本是2.45.0

更新 2

我运行无头地宁火狐

我在 ubuntu 中使用 Firefox 39selenium 2.46.0 尝试了你的脚本,它工作正常

我认为您的 Selenium 版本可能与您的 Firefox 版本不兼容。尝试使用硒 2.46.0

您可以获得 selenium 2.46.0 的 Maven 依赖项 here

希望这对你有帮助...

编辑

您的主要问题是,您没有运行安装 X-Server,因此 Firefox 无法连接到显示器。这就是为什么你得到

Error: no display specified

哪个应该是你的主要问题...

要解决这个问题,您需要设置 Xvfb 或 "real" X-Server,具体取决于您拥有的服务器类型并正确处理它的暴露显示(即 运行 您的 selenium如果您的 xvfb 恰好在显示器上 运行ning :1),则带有 DISPLAY=:1 的服务器进程。

This site helped me to get a hold of this issue some time back. Alternatively check out the docker-selenium 来自 Selenium 本身的项目。如果你有办法在你的机器上启动一个 docker 容器,那应该是解决这个问题的最快方法(如果没有,通过他们的文件可以很好地理解如何设置无头的 Selenium 环境在 ubuntu 机器上)

祝你好运,欢迎来到这个叫做无头测试的舒适地狱部分;)