paint-brush
Running Selenium Tests with Chrome Headlessby@eliasnogueira
13,814 reads
13,814 reads

Running Selenium Tests with Chrome Headless

by Elias NogueiraJune 7th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Before <a href="https://hackernoon.com/tagged/google" target="_blank">Google</a> <a href="https://hackernoon.com/tagged/chrome" target="_blank">Chrome</a> 59 the headless execution must be done by 3party headless browsers like <a href="http://phantomjs.org/" target="_blank">PhantomJS</a>, <a href="https://slimerjs.org/" target="_blank">SlimerJS</a>, <a href="http://triflejs.org/" target="_blank">TrifleJS</a>, <a href="http://www.nightmarejs.org/" target="_blank">Nightmare</a>, and HTMLUnit.

Company Mentioned

Mention Thumbnail
featured image - Running Selenium Tests with Chrome Headless
Elias Nogueira HackerNoon profile picture

Introduction

Before Google Chrome 59 the headless execution must be done by 3party headless browsers like PhantomJS, SlimerJS, TrifleJS, Nightmare, and HTMLUnit.

The "problem" is that these headless browsers emulate some engines, but not V8 (Chrome engine).




PhantomJS | QtWebKitSlimerJS | Gecko (Firefox)TrifleJS | Trident (Internet Explorer)Nightmare | Electron

When we talk about testing, and most of the users in various segments use Google Chrome, it's necessary to simulate the real engine.

How to do it with Java

As Google Chrome shipping headless in version 59 (as you can see here) we can tell to ChromeDriver the options before the execution.

In the code below I added two options through ChromeOptions: headless and the window-size.

The headless option will tell Google Chrome to execute in headless mode.

The window-size is a way to control the responsiveness (may your site be displayed as a mobile site if you not set a window size).


You can see another way to inform the ChromeOptions herehttps://sites.google.com/a/chromium.org/chromedriver/capabilities