ubuntu cli 中的 Firefox GLib-CRITICAL 错误

标签 firefox ubuntu selenium testing jenkins

我已经在我的 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 正在运行的主要脚本

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

我正在 headless 运行 firefox

最佳答案

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

Error: no display specified

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

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

This site帮助我在一段时间前解决了这个问题。或者查看 docker-selenium来自 Selenium 本身的项目。如果你有办法在你的机器上启动一个 docker 容器,那应该是解决这个问题的最快方法(如果没有,通过他们的文件可以很好地理解如何在 ubuntu 机器上设置 headless 的 Selenium 环境)

祝你好运,欢迎来到这个叫做 headless 测试的舒适 hell 部分;)

关于ubuntu cli 中的 Firefox GLib-CRITICAL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934616/

相关文章:

firefox - nvd3 图表在 Firefox 中无法正确加载

javascript - 如何使用 Perl 和 Mechanize 在网页上单击此按钮

javascript - 在使用 Selenium 自动执行测试时如何处理在调试器中暂停的覆盖

html - 如何在 CSS 文件中更改 safari 和 opera 的字体大小而不是 chrome。

javascript - Firefox 扩展无法覆盖元素事件

MySQL docker 中的 MySQL conf 文件

ubuntu - XDebug 无法打开远程调试文件 '/var/log/xdebug/xdebug.log'?

c# - Ubuntu 上的 Mono 堆栈/堆损坏导致段错误

java - 如何使用 Selenium 和 Xpath 通过忽略大小写的文本查找元素

java - Selenium 屏幕捕获 - 图像不可用