在没有显示的Linux服务器上运行Chrome WebDriver

发布于 2024-11-29 04:46:39 字数 278 浏览 4 评论 0原文

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

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

I'd like to run automated tests using selenium2's chrome webdriver on a linux server.

I've already set up firefox to run on the server by using Xvfb (See http://www.semicomplete.com/blog/geekery/xvfb-firefox.html) and would like to do something similar with chrome. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小梨窩很甜 2024-12-06 04:46:39

我面临着同样的挑战,用 selenium + chromedriver 设置 Linux 盒子,
这是我的注释:

先决条件:

  1. 安装 JRE 来运行 selenium jar

  2. 安装 selenium 服务器

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

  3. 安装 xvfb(您似乎已经完成了这部分)

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

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

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

运行:

  1. 运行 xvfb

Xvfb:1 -屏幕 5 1024x768x8 &

导出 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 设置为 {chromedriver 的位置}

10:07:34.258 信息 - 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< /a>

干杯!

I was facing the same challenge of setting a linux box with selenium + chromedriver,
and here's my notes:

Pre-reqs:

  1. Install JRE to run the selenium jar

  2. Install the selenium server

    grab the jar file from https://code.google.com/p/selenium/downloads/list)

  3. Install xvfb (you've seem to have already achieved this part)

  4. Install google-chrome for your linux distribution

  5. Download the chrome driver
    You can grab it from here: https://sites.google.com/a/chromium.org/chromedriver/downloads

  6. Install other selenium dependencies that you might need (but the above is the minimum to get chromedriver to work)

To run:

  1. Run xvfb

Xvfb :1 -screen 5 1024x768x8 &

export DISPLAY=:1.5

  1. Run the selenium server jar with ChromeDriver options.
    It'll look something like this:

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

  1. The selenium server log should output something similar to this:

Mar 19, 2013 10:07:27 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server

Setting system property webdriver.chrome.bin to {location of google-chrome}

Setting system property webdriver.chrome.driver to {location of chromedriver}

10:07:34.258 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub

10:07:34.259 INFO - Version Jetty/5.1.x
10:07:34.259 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
...

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

Cheers!

つ可否回来 2024-12-06 04:46:39

根据以编程方式将EnvironmentProperty设置为ChromeDriver,您可以执行以下操作:

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

这是withEnvironment 的文档

According to SetEnvironmentProperty to ChromeDriver programatically you can do the following:

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

Here is the documentation for withEnvironment

我一直都在从未离去 2024-12-06 04:46:39

我还没有找到一种方法可以像使用 FirefoxBinary 那样以编程方式为 ChromeDriver 执行此操作。

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

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

I haven't been able to find a way to do this programmatically for the ChromeDriver like you can with the FirefoxBinary.

I've submitted a improvement request which has a patch attached to allow this. You can see it here: http://code.google.com/p/selenium/issues/detail?id=2673

Edit:
You can see below response from Stephen on how to use this now the change has been merged.: https://stackoverflow.com/a/16619608/998442

战皆罪 2024-12-06 04:46:39

我明白你想要做什么,但你可能只是运行硒网格。它是为自动化浏览器测试而设计的。在服务器上运行良好。

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

I get what you are trying to do, but you probably just run selenium grid. It was made for automated browser testing. Works great on a server.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文