Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run Chrome headless from protractor WITHOUT using a Selenium server

I have Chrome working headless via a Selenium server by running xvfb bound to DISPLAY:10 and then running Selenium with a DISPLAY=:10 webdriver-manager start. So that's all fine.

I also have Chromedriver running directly from protractor by specifying directConnect: true in my protractor.conf.

What I'd like to do is a combination of the two, ie. run chromedriver directly (NO SELENIUM!), but somehow instruct it to run headless on DISPLAY :10.

In terms of topology, everything is run on the developer's PC. There are no servers involved. In a comment below, I mention a node server: this is being used to launch protractor instead of the more usual launching from the command line. I want protractor to be running on DISPLAY:0 so I can see its output, test failures etc. When it spawns chrome using chromedriver, I want chrome to be running on DISPLAY:10. My reason for doing this is that I want the chrome window to be bigger than my physical screen. See How can I screenshot the full height of a mobile form factor? for background.

like image 339
pinoyyid Avatar asked Feb 19 '16 10:02

pinoyyid


People also ask

How do you run a Chrome headless protractor?

To start Chrome in headless mode, start Chrome with the --headless flag. As of Chrome 58 you also need to set --disable-gpu , though this may change in future versions. Also, changing the window size during a test will not work in headless mode, but you can set it on the commandline like this --window-size=800,600 .

How do you run a protractor in headless mode?

Headless Chrome with Protractor With a protractor, we can achieve a headless chrome browser by using args: [ "--headless", "--disable-gpu", "--window-size=800,600" ] tags. Headless Chrome mode has been available on Mac and Linux since Chrome 59; Windows support came in Chrome 60.

How do I run Selenium headless in Chrome?

You can run Google Chrome in headless mode simply by setting the headless property of the chromeOptions object to True. Or, you can use the add_argument() method of the chromeOptions object to add the –headless command-line argument to run Google Chrome in headless mode using the Selenium Chrome web driver.

How do I run Chrome in headless mode in Java?

ChromeOptions options = new ChromeOptions();options. addArguments("--headless");WebDriver driver = new ChromeDriver(options); That is all. You can run it.


Video Answer


2 Answers

I'm guessing the topology is like this:

  • Box A: xvfb, DISPLAY=:10, Selenium Server, chromedriver
  • Box B: DISPLAY=:0, node, protractor (directConnect: true), chromedriver
  • Box C: test runner.

I don't know how else it could be laid out, given that DISPLAY is an environment variable, not a parameter to be passed.

In which case, assuming you don't want a separate xvfb installed on Box B, and A is reachable (plus a decent connection) from B, the solution is simply to set:

DISPLAY=boxAHost:10

on Box B.

If A isn't reachable from B, it might be simplest to just duplicate the xvfb setup on both A and B, and have DISPLAY=:10 on both.

like image 153
Andrew Regan Avatar answered Dec 25 '22 20:12

Andrew Regan


I had a "Doh!!!" moment of zen and the whole thing is much easier that I thought it would be.

I had conflated the stdout of node/protractor (which I want on my screen) with the X display of chrome (which I want headless on DISPLAY:10). Of course they are totally different!!!!

Simply prefixing protractor with DISPLAY=:10 eg.

DISPLAY=:10 protractor /installation_test/conf-c-direct-noserver.js

or, in my case since I'm running a node server which in turn spawns protractor, ...

DISPLAY=:10 npm start

So protractor runs in my terminal and I can watch stdout, whereas the DISPLAY=:10 is inherited down through the call layers and is eventually seen and understood by Chrome.

like image 23
pinoyyid Avatar answered Dec 25 '22 19:12

pinoyyid