When we launch a browser using Selenium WebDriver, by default it is not in its maximized state. In this post, we will see how to maximize and minimize a browser during automation.
Maxmize a browser
During automation, it’s one of the best practices to maximize the browser in the initial phases (or in the @BeforeTest method in case you are using TestNG as the testing framework). The following command can be used to maximize the browser window.
Minimize a browser
Unfortunately, Selenium WebDriver doesn’t provide any native support for minimizing a browser. If we don’t want to see the browser in action during automation than we can use Headless browsers like HTMLUnitDriver, PhantomJS, etc. But in case we specifically want to minimize a browser during automation than we can make use of the below statement. The following code snippet will position the browser to an area that is not within the viewable section of the machine we are working on. Thus making it appear as if the browser window got minimized.
driver.manage().window().setPosition(new Point(0, -1000));
That’s all we have in this post, comment below if you have any queries. Also please share this post with your friends and don’t forget to check our complete selenium tutorial here.
Kuldeep is the founder and lead author of ArtOfTesting. He is skilled in test automation, performance testing, big data, and CI-CD. He brings his decade of experience to his current role where he is dedicated to educating the QA professionals. You can connect with him on LinkedIn.