Headless browser Testing using Selenium HtmlUnitDriver

Hello Welcome to Selenium tutorial, today we will see how to perform Headless browser Testing using Selenium HtmlUnitDriver.

Headless refer which we can’t see on UI.

Headless browser Testing using Selenium

If you have ever worked on Firefox, Chrome, IE browser in Selenium you might have faced so many issues like xpath is changing everytime when a new feature is getting added.Using these browsers, some common issue which I faced during my daily automation like Sync issues and speed as well. Some browser takes the time to load in my experience I faced performance issues with IE browser.

To  increase the speed of your test script i.e. performance of your script we can try some testcases using Headless browser Testing using Selenium.

What is Headless testing/Headless browser in Automation?

Advantage and Disadvantage of headless browsers or Why should I use this?

How to perform Headless testing in Selenium Webdriver using HTMLUnitDriver.

What are the common issues or limitation while working with Headless browsers?

So let us discuss each topic separately.

What is Headless testing/Headless browser in Automation?

Ans-A browser, which does not have any GUI it means which runs in the background. If you run your programs in Firefox, Chrome, IE and the different browser then you can see how the browser is behaving but in headless browsers, you cannot .

Advantage and Disadvantage of headless browsers or Why should I use this?

Ans-One of the most Important advantage is Performance.

1-When we run your test case using headless browsers then you will get the result just in seconds, you will see the result in below program.

2-When we have to run a test case to create some sample test data or just you have to verify some messages and functionality then you can try headless browsers.

3- When we have to run the test case on the remote machine or server, which does not have any browser, but still you have to execute test case then you can try with headless browsers again.

I hope you get the clear picture of this so let us start with some program and output as well.

There is so many headless browsers available in the market, which does the same like Nodejs etc.

When you build your test case using Jenkins then also it runs in Headless mode.

 

Here is the quick video for Headless testing using HTMLUNITDriver

 

 

Headless browser Testing using Selenium

To implement Headless testing selenium have inbuilt class known as

HtmlUnitDriver like other browsers like FirefoxDriver, ChromeDriver etc.

You can find the official https://code.google.com/p/selenium/wiki/HtmlUnitDriver

Before moving to the program, you should have the setup ready. If you have not done setup then no worry use download and Install

Java, Eclipse, Selenium Webdriver Jars, Latest Release

Program-Headless browser Testing using Selenium

Output

Title of the page Welcome to Facebook – Log In, Sign Up or Learn More

After login, title is = Facebook

In above program, you will notice it will take only 3-4 seconds to give you the result but if try the same in other browsers it will take 15-20 seconds.

Javascript supports in the HtmlUnitDriver

All the browser which  we are using they use separate javascript engine, but HTMLUnitDriver use Rhino engine so if you will test some javascript applications then chances are high you will get diff results.

By default, JavaScript is disabled in HTMLUnitDriver so you have to enable it while writing the script.

Two ways to enable javascript in HTMLUnitDriver

First- setJavascriptEnabled method to true

 Second- While initializing browser itself you can enable. 

Thanks for visiting my blog. Keep in touch.

Have a nice day 🙂

38 Comments

  1. Kavya Chitra
  2. Hari
  3. Sue
  4. Lae
  5. Suman
  6. Naresh