Headless Testing:
Headless testing is execution of automated UI based test cases without launching browser. Test scripts are being executed but without initializing browser itself. Headless execution is not useful for functional testing but for automation testing its awesome.
Headless browser execution is faster than real browser:
Execution of test scripts is way faster than real browsers. This is one of the best pros for using headless browser testing. Because we are not starting browser UI to load CSS, Javascript. Hence, it saves time. Top Software testing Companies are using headless browser execution because sometimes it is faster 2 times to 15 times than the real browser.
Headless browser for Unit testing:
People working in Software testing services company are using headless browser execution for Unit test cases to save tremendous amount of time. You can simulate multiple browser versions on the same machine.
When Headless browser is not used:
Headless browser execution is not useful when people want to watch the test script execution.
Example of Headless browsers:
Google Chrome
Firefox
PhamtomJS
HtmlUnit
Automation code to initialize the Headless chrome browser using Java/Selenium:
System.setProperty(“webdriver.chrome.driver”, chromeDriverPath);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("–headless");
ChromeDriver driver = new ChromeDriver(chromeOptions);
Also, Selenium supports headless testing using its class called HtmlUnitDriver. This class internally uses HtmlUnit headless browser.
Code to initialize HtmlUnitWebDriver with Java script support is as follows: [HtmlUnitDriver allows you to select the version of browser that you would like to run your tests on]
HtmlUnitDriver unitDriver = new HtmlUnitDriver();
unitDriver.setJavascriptEnabled(true);
unitDriver.get(“http://google.com”);
Hope this information is very helpful for you.