Regarding issue with using ChromeDriver with Xvfb

34 views
Skip to first unread message

Vinit Sharma

unread,
Aug 2, 2016, 7:51:41 AM8/2/16
to webdriver
Hello there,
                  The main functionality which I want to achieve is a "headless Chrome in Ubuntu". I have written my testcases in java. Initially I was using PhantomJSDriver class for creating driver object in my testcases, it makes use of a phantomjs executable to run the testcases in phantomjs headless browser, in Ubuntu. The only problem encountered with phantomjs headleess browser is that it shows several javascript errors which are not shown in either Chrome or Firefox. So I googled for having Chrome as a headless browser. I came through the concept of using Chrome in headless way or we can say virtually by making use of ChromeDriver class under WebDriver reference in java testcase files, and using it with Xvfb (which is X Virtual Frame Buffer). I downloaded latest ChromeDiver which is 2.22. Also I tried creating the driver object as under: 


ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
.usingDriverExecutable(
new File("location/to/chromedriver"))
.usingAnyFreePort().withEnvironment(
ImmutableMap.of("DISPLAY", ":1")).build();
chromeDriverService.start();
driver = new ChromeDriver(chromeDriverService);

But I am unable to create the driver object as stated in the above code. The exception which I am getting is Unable to open the browser. Please help me provide a demo through which I can run a headless Chrome in Xvfb and also I would like to know which all required java dependencies jars I need to add along with this ChromeDriver. Any help would be appreciated. Thanks.

Serguei Kouzmine

unread,
Aug 3, 2016, 11:22:37 PM8/3/16
to webdriver
Hello Vinit

You need to also start xvfb with the command

export DISPLAY=:$DISPLAY_PORT
# TODO : specify geometry of the display
Xvfb $DISPLAY -ac >/dev/null 2>&1 &


https://www.x.org/archive/X11R7.6/doc/man/man1/Xvfb.1.xhtml
Reply all
Reply to author
Forward
0 new messages