Running Chrome WebDriver on a linux server with no display
Asked Answered
C

4

31

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?

Crystacrystal answered 11/8, 2011 at 9:56 Comment(1)
Yes, that should work just fine. What have you tried?Cerulean
G
7

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://mcmap.net/q/463781/-running-chrome-webdriver-on-a-linux-server-with-no-display

Glyco answered 17/10, 2011 at 2:44 Comment(2)
it appears your improvement request is marked as fixed. could you change your answer to explain how to use your fix?Starter
Updated to add link to below response from Stephen showing how to set the display environment variableGlyco
P
26

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!

Parve answered 20/3, 2013 at 2:44 Comment(0)
L
11

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

Lingonberry answered 18/5, 2013 at 0:36 Comment(0)
G
7

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://mcmap.net/q/463781/-running-chrome-webdriver-on-a-linux-server-with-no-display

Glyco answered 17/10, 2011 at 2:44 Comment(2)
it appears your improvement request is marked as fixed. could you change your answer to explain how to use your fix?Starter
Updated to add link to below response from Stephen showing how to set the display environment variableGlyco
R
0

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/

Remediable answered 29/4, 2020 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.