Understanding Headless Browser testing
Headless browser testing is type of browser testing without the head, meaning presence of any browser GUI. We can access webpage without showing the users that scripts are running in the backend.
Why Headless browser Testing?
Headless browser testing is a useful approach and can be used for the following benefits:
Headless browser testing is faster than real browsers since they do not come with all the overhead of starting up a browser GUI, and this equates to quicker results for your tests.
Headless browser testing can facilitate a lot of layout checks like test style elements such as page layouts (e.g. determining the default width of the page, the coordinates of where an element is), colour selection for any elements, font used, etc. You can even automate screen captures for layout checks.
It is much easier and quicker to navigate to a website heedlessly, scrape for data, and use the results to test multiple webpages as part of a quality control effort.
Looks impressive, isn’t. However, we must also consider the constraints and limitations of using headless browser testing.
- Debugging is very difficult in headless browser testing.
- It can be limiting, if you want to test on the full variety of browser and OS combination to ensure coverage.
- It can be limiting, when performing full UI tests, as it won’t interact with the browser the way your users would.
Do, all browsers support headless testing? Here is a list.
Browsers supporting headless testing
Some of the important headless browsers are listed below:
- Headless Chrome
- Headless Firefox
- Selenium WebDriver
Following script can be used to use PhantomJS with Selenium:
DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, “drivers/phantomjs.exe”);
WebDriver driver = new PhantomJSDriver(capabilities);
HTML Unit Driver is the lightest weight and fastest implementation headless browser for of WebDriver. It is based on HtmlUnit. It is known as Headless Browser Driver. It is same as Chrome, IE, or Firefox driver, but it does not have GUI so one cannot see the test execution on screen.
To use it in Chrome and Firefox:
Using Google Chrome:
System.setProperty(“webdriver. chrome. driver”, “drivers/chromedriver.exe”);
ChromeOptions options = new ChromeOptions ();
WebDriver driver = new ChromeDriver(options);
FirefoxBinary firefoxBinary = new FirefoxBinary ();
System.setProperty(“webdriver. gecko. driver”, “drivers/geckodriver.exe”);
FirefoxOptions firefoxOptions = new FirefoxOptions ();
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
How to conduct tests if you are behind a proxy?
If you are behind a proxy server additional configuration has to be done along with the headless browser configuration.
HtmlUnitDriver driver = new HtmlUnitDriver();
Proxy proxy = new Proxy();
proxy. setHttpProxy(“PROXY_HOST, PROXY_PORT”);
ArrayList cliArgsCap = new ArrayList();
DesiredCapabilities caps = new DesiredCapabilities();
driver = new PhantomJSDriver(caps);
Automated headless browser testing is great for when you need fast feedback on components of your application. They are quick to set up, and can ensure that snippets of code are working with the end-to-end experience.
In this tutorial, we explained how to verify tool tips using Selenium. You can go and read more Selenium tutorials published on this blog.
Are you looking to become an Automation tester?
Techcanvass offers Automation Testing and Business Analysis certification courses. We are an IIBA endorsed education provider (EEP), iSQI Germany Authorized Training as well as Agile Testing alliance partner for CP-SAT certification training in Selenium.
One of the key features of our courses is the Job readiness package, as shown below: