O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Controlling Windows processes

Selenium WebDriver Java bindings provide the WindowsUtils class with methods to interact with the Windows operating system. During test runs, there might be a need to close open instances of browser windows or processes at the beginning of the test. By using the WindowsUtils class, we can control the process and perform tasks, such as killing an open process, and so on.

In this recipe, we will use the WindowsUtils class to kill the open browser window.

How to do it...

Let's close an open instance of Firefox by using the WindowsUtils class in the setUp() method as follows:

@Before public void setUp() { WindowsUtils.tryToKillByName("firefox.exe"); driver = new FirefoxDriver(); driver.get("http://www.google.com"); driver.manage().window().maximize(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required