HTMLUnit Driver with Selenium

We know Selenium Webdriver is a web automation tool. Which enables you to run your tests against different browsers. These browsers can be Internet Explorer, Firefox or Chrome. To use a particular browser with Selenium you need the corresponding driver.

 

In Selenium Tests, Selenium launches the corresponding browser called in a script and executes test steps. You can see the browser and the test execution in action but HTMLUnit is the headless browser, Unlike Firefox, Chrome, and IE it doesn’t have any GUI. It’s a non-GUI based browser.

 

HTMLUnit Driver

HTML unit driver is the headless or Non-GUI based browser that’s why it is the lightest weight and fastest implementation browser. It is same as Chrome, IE, or FireFox driver, but it does not have GUI so one cannot see the test execution on screen.

 

Let’s run our Selenium Sample Test again but this time with HTMLUnit browser instead of Firefox and verify the Test Result.

 

Let’s see the Test report of the above Test Case.

HTMLUnit Driver with Selenium

 

This is our test report. Have you noticed, the execution time for the same test case reduced? The Same Test is taking 14 Sec to execute with HTMLUnit driver While this test was taking 41 sec with Firefox.(See Sample Selenium Test)

It is recommended to practice the same code on your local machine. Please note when you will run the Test with HTMLUnit driver, you will not see any open browser. HTMLUnit is the non-GUI based browser.

 

Advantage of HTMLUnit Driver or Headless Browser

Let’s see the advance of the headless browser over GUI based browser.

  1.  Execution Is faster compared to all other driver Instances.
  2. Since it is not using any GUI to test, your tests will run in the background without any visual interruption.
  3. It Is platform Independent as It Is pure Java solution. It Is using Rhino javascript engine.
  4. It is platform independent and easier to run several tests concurrently. Ideal for Load Testing.

 

So this is all about how to use and execute Test case with HTMLUnit or Headless browser. If you want fast and light execution on your server then you can use HTMLUnit driver.

 

SeleniumTutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

0 Comment

Leave a Reply