Hi Readers, In this blog, I am going to explore, how to run an automation script in headless mode for Gmail login.
headless browser executes a script without UI(Graphical user Interface). It can run without a real browser means in the system, if a browser is not installed still script will be executed with the help of headless. In this case, parallel execution is possible. Equally, users can perform other tasks simultaneously and the users run the script in headless mode then which is faster than actual UI testing.
Why use a headless browser for test execution?
We use a headless browser for test execution because it provides benefits like-
- It helps in CI pipeline
- It helps in Web Scraping
- It’s faster execution
- Supports for multiple browser version
Arguments in Script for headless-
We need to define the different arguments- window size, headless, start maximized, etc in the script.
There are various arguments like below-
ChromeOptions option=new ChromeOptions(); option.addArguments("start_maximized"); option.addArguments("disable-infobars"); option.addArguments("disable-extensions"); option.addArguments("--headless"); option.addArguments("--window-size=1920,1080"); option.addArguments("--window-size=1920,1080","--disable-gpu", "--disable-extensions", "--no-sandbox", "-incognito");
In the above code, in the headless mode using the addArguments() method of the ChromeOptions class provided by the Selenium WebDriver.
Selenium Support for Headless Browsers:-
In Selenium, We need to build some libraries and import some classes.
1. Go to Automation IDE- To get started, open the “Preferences” window in Eclipse. Navigate to “Java » Build Path » User Libraries” on the left-hand side and click the “New” button. Enter the library name and click the “OK” button (leave the “System Library” checkbox alone)
2. Find the locators– find the locators according to Gmail account sign-in and write the script-
Selenium WebDriver provides a class for Chrome Browser is ChromeOptions, which can specify certain configurations to change the default behavior of Chrome.
For the Firefox browser, Selenium WebDriver provides a class is FireFoxOptions.
For the Edge browser, Selenium WebDriver Provides a class is EdgeOptions.
I hope you enjoyed it and it helped you!! stay connected for more future blogs.