Headless Web Driver testing with Chrome on Headless Servers

Recently, I had a task to migrate the WebDriver based test cases from PhantomJs to Chrome headless and the tests were running on headless CI docker containers. The migration was not a smooth journey as I had anticipated and this article is based on my learning experience during this migration.

PhantomJs was widely used for headless testing and now it has been unofficially abandoned by the PhantomJs team. So we had to switch to some other browser which is under active development and also which supports headless mode. The choice was Google Chrome (or Chromium).

As more and more organizations move towards cloud containers or virtual machines to run their CI build, it is quite important to have the ability to run your WebDriver based tests in headless mode.

My key learnings from this migration:

  • Avoid using Xvfb (Virtual Frame Buffer) as virtual display when your test suite has hundreds of test cases.  Xvfb crashes in the middle of the test for unknown reason and Chrome fails to startup. Alternative is to use Chrome's native headless capability when running on headless CI Servers
  • Browser Mob Proxy is an Open Source Library, which helps to manipulate http request headers in Chrome browser. PhantomJs was supporting additional request headers by itself, however for migrating to Chrome, we had to use Browser Mob Proxy
  • Chrome doesn't allow to ignore ssl errors for non-localhost domains only in headless mode. This was quite annoying, because in normal mode, Chrome seems to ignore the SSL errors for any domain (like evil.example.com), however it doesn't load the same page in headless mode. I wonder, why Chrome behaves differently in headless and normal mode

I have created a public GitHub repository to demonstrate the headless testing with Chrome with Travis CI running on the cloud.  Please share your thoughts and feedback through LinkedIn or Google blogs or GitHub repository.

GitHub Repository:

https://github.com/harishkannarao/ChromeHeadlessTesting

Travis CI configuration file:

https://github.com/harishkannarao/ChromeHeadlessTesting/blob/master/.travis.yml

Travis CI build:

https://travis-ci.org/harishkannarao/ChromeHeadlessTesting

Comments

Popular posts from this blog

JSON with curl and jq

Import self signed in Linux for Chrome / Chromium headless testing

Colima - Drop In replacement for Docker Desktop for Mac and Linux