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(); ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.