Protected by Copyscape
Powered By Blogger

Wednesday, April 21, 2021

How to run your Selenium test in headless mode with the available browsers? What are their advantages & disadvantages for the same?

Running test in headless mode, using Selenium API, will increase the execution speed as all the execution will be carried out without the involvement of any UI.

Until recently, modern browsers like Chrome and Firefox did not offer any built-in support for running their browsers in Headless mode. QA engineers would use open-source headless browsers such as PhantomJS or Zombie JS to achieve this purpose. However, much-awaited headless mode is made available, for Chrome 59 and Firefox 56 versions and higher.

Now, we will see that what changes needs to be done in the code to run the script in headless mode for each browser.

  • Chrome
  • Firefox
Chrome

ChromeOptions options=new ChromeOptions();
options.addArguments("--headless");

WebDriver driver=new ChromeDriver(options);

Firefox 

FirefoxOptions firefoxOptions=new FirefoxOptions();
firefoxOptions.setHeadless(true);
driver=new FirefoxDriver(firefoxOptions);

Advantages of Headless Browser Testing

Since Headless browsers, do not have a GUI, they save a lot of resources and time. Following are some of the biggest advantages of headless browser testing:

  • Improves speed and performance – Since this type of testing does not actually open a browser, the system saves the processing power that would be used in a real browser test. Due to this, the tests are executed faster.
  • Allows testing browser-less setups – There may be setups where installing a browser is not possible, such as servers. In these cases, headless browsers help run automation tests easily.
  • Makes multi-tasking possible – One can use the browser or machine to continue doing other work, while the tests run in the background. This saves a lot of hours that is, otherwise, spent staring at the screen.
  • Minimum Human Intervention – There are fewer chances of failure and reduced errors due to minimum ‘human intervention.’
  • Taking Screenshots is Possible – Any desired screenshots are still stored, just like in regular automation testing.

Disadvantages of Headless Browser Testing

Running tests on headless browsers do have a few disadvantages. Some of them are as follows:
  • Lacks Actual User Experience- Running headless tests cannot give real feel and experience. One cannot really mimic the real user experience.
  • UI issues can’t be identified– Cosmetic bugs can’t be identified while doing headless browser testing. Issues like the location of a button or colour of a web element, etc. cannot be identified.
  • Hard to debug inconsistent failures– When it comes to debugging, headless browsers may not be the best option to find out Inconsistent errors and failures.
Limitations
  • Rendering: User could not feel how UI is rendering.
  • Resizing & page height: User cannot resize the page in headless testing.
  • User cannot use IE10, IE11, Edge, Opera & Safari for headless testing.

I will keep adding more automation concepts in my upcoming posts. Please keep me posted if you have any questions and concerns.



Best of Luck.

No comments: