Friday 26 October 2018

How to use browser options to run in headless mode?

How to use browser options to run in headless mode?



First of all let us understand what is the meaning of headless mode. Headless mode is when you don't see browser GUI appearing but execution would go on in the back end. Where this would be useful?

1> When you want to only test the functionality of application and less care about GUI.
2> Also let's say there is huge data to be created using GUI and you don't want to see the browser GUI as it would be faster in headless mode.
3> You are running your tests in Jenkins CI machine where you don't want browser GUI to appear.


Chrome in headless mode: 

3.x version of Selenium allows using ChomeOptions class to pass headless options as given below:


ChromeOptions options = new ChromeOptions();
// option for headless mode
options.addArguments("--headless");

OR

options.setHeadless(true);

This options reference variable you will have to pass in ChromeDriver object like this:

WebDriver driver = new ChromeDriver(options);


Then, whatever code you have underneath, it will execute in backend and no longer open chrome browser GUI.

Firefox in headless mode: 


3.x version of Selenium allows using FirefoxOptions class to pass headless options as given below:


FirefoxOptions options = new FirefoxOptions ();
// option for headless mode
options.addArguments("--headless");

OR

options.setHeadless(true);

This options reference variable you will have to pass in FirefoxDriver object like this:

WebDriver driver = new FirefoxDriver (options);


Then, whatever code you have underneath, it will execute in backend and no longer open chrome browser GUI.

Internet Explorer in headless mode: 

Helium uses Selenium's InternetExplorerDriver to drive IE. Unfortunately Microsoft has not yet made IE11 fully compatible with this driver. So options like headless mode is not available in IE. It has to be run in GUI mode only. 




If you have any questions about this do write in comment below. 

Hope this blog has been useful to you. If yes do follow my blogs by entering your email by 
clicking on "Follow" (blue) button. 

You can as well explore my 

Youtube Channel: https://www.youtube.com/user/srinivaskinik

And 

facebook page: https://www.facebook.com/srinivaskinikalmady/

Thank you.

No comments:

Post a Comment

How to schedule RFT (Rational Functional Tester) scripts to run using Jenkins / schedule

How to schedule RFT (Rational Functional Tester) scripts to run using Jenkins / schedule 1. Create a batch file with following content ...