无法运行java无头硒

时间:2016-10-05 06:33:49

标签: java selenium amazon-web-services firefox

我试图在java中运行selenium脚本。但每次我试图创建firefox驱动程序我都会收到此错误

[WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows: 

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

(firefox:32000): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback 'C' locale.
Error: no display specified

关于我的问题的一些背景知识。

  1. 我尝试在aws ec2
  2. 上使用ubuntu 14.0.4运行selenium
  3. 我已经尝试安装xvfb,因此firefox可以在无头模式下运行并运行带有一些引用的xvfb(https://medium.com/@griggheo/running-selenium-webdriver-tests-using-firefox-headless-mode-on-ubuntu-d32500bb6af2#.u0hrlct41https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
  4. 我可以毫无问题地运行selenium python脚本
  5. 我在我的java selenium脚本" org.seleniumhq.selenium"中使用了这个selenium sbt。 %" selenium-java" %" 2.53.1",
  6. 任何人都可以帮助我使用java运行无头硒吗?

2 个答案:

答案 0 :(得分:1)

如果您想在无头模式下运行Selenium java测试套件,请按照以下步骤操作。您可以在无头模式下运行Chrome浏览器。祝你好运!

1) /usr/bin/Xvfb :1 -screen 0 1024x768x24 &

2) export DISPLAY=:1

4) make all version same 2.53.1 for selenium

5) add profile for chrome 

6) Add chrome driver (Linux version) in test resorurces folder.

答案 1 :(得分:0)

不知怎的,我确实设置了java selenium无头。

我尝试使用新的ubuntu 14.0.4机器并按照此链接

http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/

一些重要的事情,你必须做笔记!

  1. 确保您的selenium版本与您的firefox版本兼容(在我的情况下,我使用selenium 2.53.1 和firefox 47.0.1

  2. 每当我ssh我的服务器时,我必须重新运行xvfb并设置本地变量。

相关问题