[Automation] Selenium Headless Chrome

[Automation] Selenium Headless Chrome

Hikari

I usually using headless to run automation script because it's a very useful mode for automated testing. Today i will introduce to you Headless mode.

So what is headless mode? It 's a mode that operates without displaying the screen which was delivered from Google Chrome 59. It means you can run auto script and don't need to launch a browser and I think it makes your script run faster, avoid to face some challenges such as slow rendering on the browser, interference of other applications running on the system.

Benefits of headless browser for test execution

  • Useful in CI pipeline: When we need to execute automated test cases remotely on server and release pipelines for continuous integration server like Jenkin, it is not always possible to install real browsers on remote machines.
  • Beneficial in web scraping: When you want to write a web scraper or data extractor that needs to visit some websites and collect data, headless browsers are a perfect choice.Because we are not concerned about functionality in these case, we just want to visit web pages and get data.
  • Support for multiple browser versions: Sometimes, the tester would like to simulate browser version on the same machine. In that case, you would want to use headless mode because most of them support the simulation of different versions of browsers.
  • Faster test execution: The performance with headless mode is better than with normal way. The real browsers like Google Chrome, Firefox, and Internet Explorer take an amount of time to load CSS, JavaScript, Image and render HTML. Headless mode does not require all this and will start performing without waiting for a page load completely.
  • Multi Tasking: You can use your browser of your machine to do anything else while tests are running in the background.

Using Headless Chrome from Selenium

Using Headless doesn't have too much difference than using regular Chrome. Operate Chrome from Selenium through Chrome Driver. Pass ChromeOptions as an argument when creating Chrome's WebDriver and specify the path, argument of Chrome to execution.

Sample code:

To Conclude

Understanding headless mode and getting used to it will be very useful with scriptors.
If you want to become a master automation engineer you need to have deep understanding how to use test management tools and settings to make your test execution become easier. So now you got the knowledge about headless mode and you can research more anything else about other mode. Thank you for your reading.