【问题标题】:Running Chrome WebDriver on a linux server with no display在没有显示的 Linux 服务器上运行 Chrome WebDriver
【发布时间】:2011-10-24 20:01:52
【问题描述】:

我想在 linux 服务器上使用 selenium2 的 chrome webdriver 运行自动化测试。

我已经使用 Xvfb 将 firefox 设置为在服务器上运行(请参阅 http://www.semicomplete.com/blog/geekery/xvfb-firefox.html),并希望使用 chrome 做类似的事情。这可能吗?

【问题讨论】:

  • 是的,应该可以的。你试过什么?

标签: google-chrome webdriver selenium-webdriver xvfb


【解决方案1】:

我明白你想要做什么,但你可能只是运行 selenium grid。它是为自动化浏览器测试而设计的。在服务器上工作得很好。

https://www.selenium.dev/documentation/en/grid/

【讨论】:

    【解决方案2】:

    我无法像使用 FirefoxBinary 那样以编程方式为 ChromeDriver 执行此操作。

    我已经提交了一个改进请求,其中附加了一个补丁来允许这样做。你可以在这里看到它:http://code.google.com/p/selenium/issues/detail?id=2673

    编辑: 您可以在下面看到斯蒂芬关于如何使用它的回复,现在更改已被合并。:https://stackoverflow.com/a/16619608/998442

    【讨论】:

    • 您的改进请求似乎被标记为已修复。你能改变你的答案来解释如何使用你的修复吗?
    • 更新添加链接到斯蒂芬的以下响应,显示如何设置显示环境变量
    【解决方案3】:

    我面临着同样的挑战,用 selenium + chromedriver 设置一个 linux 盒子, 这是我的笔记:

    前置要求:

    1. 安装 JRE 以运行 selenium jar

    2. 安装 selenium 服务器

      https://code.google.com/p/selenium/downloads/list获取jar文件)

    3. 安装xvfb(这部分你好像已经完成了)

    4. 为您的 linux 发行版安装 google-chrome

    5. 下载 chrome 驱动程序 你可以从这里获取它:https://sites.google.com/a/chromium.org/chromedriver/downloads

    6. 安装您可能需要的其他 selenium 依赖项(但以上是让 chromedriver 工作的最低要求)

    运行:

    1. 运行 xvfb

    Xvfb :1 -screen 5 1024x768x8 &

    export DISPLAY=:1.5

    1. 使用 ChromeDriver 选项运行 selenium 服务器 jar。 它看起来像这样:

    java -jar selenium-server-standalone-2.30.0.jar -Dwebdriver.chrome.bin=/path/to/google-chrome -Dwebdriver.chrome.driver=/path/to/chromedriver

    1. selenium 服务器日志应输出类似以下内容:

    2013 年 3 月 19 日上午 10:07:27 org.openqa.grid.selenium.GridLauncher main 信息:启动独立服务器

    将系统属性 webdriver.chrome.bin 设置为 {location of google-chrome}

    将系统属性 webdriver.chrome.driver 设置为 {location of chromedriver}

    10:07:34.258 INFO - RemoteWebDriver 实例应连接到:http://127.0.0.1:4444/wd/hub

    10:07:34.259 信息 - 版本 Jetty/5.1.x 10:07:34.259 信息 - 启动 HttpContext[/selenium-server/driver,/selenium-server/driver] ...

    参考: http://www.yann.com/en/use-xvfb-selenium-and-chrome-to-drive-a-web-browser-in-php-23/08/2012.html

    干杯!

    【讨论】:

      【解决方案4】:

      根据SetEnvironmentProperty to ChromeDriver programatically,您可以执行以下操作:

      service = new ChromeDriverService.Builder()
          .usingChromeDriverExecutable(new File("/path/to/chromedriver"))
          .usingAnyFreePort()
          .withEnvironment(ImmutableMap.of("DISPLAY",":20"))
          .build();
      

      这里是documentation for withEnvironment

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-17
        • 2013-04-25
        相关资源
        最近更新 更多