Minimize the Browser With Selenium WebDriver - Or Should You?

Richard Bradshaw |  |  |  | 3 mins read time

You can now minimize the browser window with Selenium WebDriver. Selenium being true to its focus on browser automation. It’s a common behaviour people do. But should you use it in your testing?

I was browsing LinkedIn this morning and I saw this post by Amon Mahajan about his latest blog post Now You Can Minimize Browser in Selenium WebDriver and immediately had to check this function out for myself. At the time of writing this post the feature was only available in Selenium version 4 Alpha 5.

Code

The code is a simple as you would have hope and come to expect from the Selenium team

driver.manage().window().minimize();

Analysis

I immediately wanted to try a simple script, so knock up a simple form submit on our automation playground. It clicks through the modals, completes and then submits the contact us form. Very simple. I test it, maximising the window as I always tend to do, and it passes in 8-9 seconds. Tidy.

Now, what if I minimise the script, will it still pass? But I was also curious to how long it would take.

The answer, it did indeed pass, but it took nearly 41 seconds! Now, this is a BETA version, and I’d be surprised if the Selenium team have really invested time in optimising this feature, because when you think a bit deeper, why would you want to use it? But 4x increase in execution speed did surprise me. I’d love to read a ‘How Selenium Works’ episode on this if David Burns ever gets to it.

But I found myself thinking, but it worked, it carried on with my scenario. It worked… ‘when was the last time you bought something, read a blog or purchased a subscription with a minimised browser window Richard?’ ermmmmm, I’ve never done that.

When Would You Use Minimise Window in Your Testing?

When running tests locally, because they take up my screen!

No. Don’t do this. If you are running tests locally you are probably doing for a few reasons. Reason 1, you don’t have a pipeline and therefore you are running them locally. Minimising the window here may make your life easier, but it would could at a cost to your tests. Your users aren’t buying your products or ordering your services with a minimised window, so don’t test that way. Your problem here is you have no pipeline, so focus on that problem.

Its Part of my Designed Test

Yes. If you can think of a valid scenario where minimising is required, absolutely. This is why I love WebDriver, because it’s about browser automation. Users minimise browsers, therefore, we may have a need to do the same during testing. However, for me the emphasis has to be on ‘valid scenario’.

I personally don’t minimise browser windows very often, if I do, its usually because I’m trying to free up my desktop to record something, or I’ve too many Chromes windows open and I only want to rotate between the ones important to me right now using the key shortcuts. I’ve only given this a few minutes of thought, but the only valid scenarios I can think of is when folk might minimise while something is processing to get it out of the way and then bring it back when they think it’s done. Or a test you really shouldn’t be automating where the user has had a window minimised for a good while and brings it back to focus and starts interacting with your site.

Conclusion

Always love seeing new features added to Selenium, then the thinking that follows where I ponder, ‘how could I use this?’. If you are testing on the UI your focus is most likely the user, so try to test considering how they use your application.

Video

Code Example

Want to learn more about Test Automation?

We offer various paid and free services to help you and your team go further by taking advantage of Automation in Testing principles

Richard Bradshaw's photo
Author

Richard Bradshaw

@FriendlyTester

Software Tester, speaker and trainer at Friendly Testing. BossBoss at Ministry of Testing. Whiteboard Testing creator. Striving to improve the testing craft.

Comments