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.
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 .
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.
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.
ChromeOptions options = new ChromeOptions();options. addArguments("--headless");WebDriver driver = new ChromeDriver(options); That is all. You can run it.
I'm guessing the topology is like this:
xvfb
, DISPLAY=:10
, Selenium Server, chromedriverDISPLAY=:0
, node, protractor (directConnect: true
), chromedriverI 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With