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(); }
How it works...
We can close or kill any process running on the Windows OS by using the tryToKillByName()
function of the WindowsUtils
class. We need to pass the name of process we wish to close.
WindowsUtils.tryToKillByName...