【问题标题】:Could't run java headless selenium无法运行 java 无头硒
【发布时间】:2016-10-05 06:33:48
【问题描述】:

我尝试在 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 上使用 ubuntu 14.0.4 运行 selenium
  2. 我已经尝试安装 xvfb,以便 Firefox 可以在无头模式下运行并使用一些引用运行 xvfb(https://medium.com/@griggheo/running-selenium-webdriver-tests-using-firefox-headless-mode-on-ubuntu-d32500bb6af2#.u0hrlct41https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
  3. 我可以毫无问题地运行 selenium python 脚本
  4. 我在我的 java selenium 脚本中使用了这个 selenium sbt "org.seleniumhq.selenium" % "selenium-java" % "2.53.1",

谁能帮助我使用 java 运行无头硒?

【问题讨论】:

    标签: java selenium amazon-web-services firefox


    【解决方案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.
    

    【讨论】:

      【解决方案2】:

      不知何故,我确实设置了 java selenium headless。

      我尝试使用新的 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 并设置本地变量。

      【讨论】:

        猜你喜欢
        • 2018-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-21
        • 1970-01-01
        • 2016-04-28
        相关资源
        最近更新 更多