In the WebDriver Series, you can read lots of advanced tips and tricks about automated testing with WebDriver. In today's publication, I am going to share with you how to speed up your tests' execution through the usage of the newest Headless Execution mode of Chrome. Moreover, I made a couple of benchmarks to compare its speed to the rest of the major browsers.

Test Case

I have created a particular HTML page that we are going to use in our tests. There I have put 100 of each of six different HTML elements- text, select, submit, color, data, and radio. Below you can find the page without the repetition of the elements.

You can find the full test page on the following URL.

Headless Execution Chrome Driver

It is quite simple to run your tests in the headless mode. You need simply to add the "headless" argument to the ChromeOptions object.

While ago when we were working on the first version of the BELLATRIX test automation framework, I did this research while I was working on a similar feature for our solution.

Benchmark against Other Browsers

Test Case

First, we open the page that I previously showed you- the one with over 600 HTML elements. Then we set some timeouts. We find all elements of each type using different locators. For the HTML 5 elements (date and color) we use a little bit of JavaScript code to set the value of the elements. For the rest of the items, we use the native WebDriver methods.

Benchmark Execution Time

To make proper conclusions about the speed of the different browsers, we will use the method Profile. It will execute the above test a specific number of times (in our case 10 times) and measure the total and average test execution times.

Benchmark Tests

These are the tests for Chrome, Chrome Headless Mode, Firefox, Edge and PhantomJS.

Benchmark Results

Browser Average Time (Seconds) 10 executions Chrome 60 Headless Mode 40.388 Chrome 60 58.509 PhantomJS 2.1 26.282 Firefox 55 85.45 Edge 40.15 11.936

As you can see the results are kind of interesting. The headless mode of Chrome performs 30.97% better than the UI version. The other headless driver PhantomJS delivers 34.92% better than the Chrome's headless mode. Surprisingly for me, the Edge browser totally beats all of them. The Firefox is the slowest.

I have run the tests using Visual Studio 2017 15.3.4 on Windows 10 Enterprise Version 1703 Build 15063.608.

Summary