Handling Windows Processes Through WebDriver

Like QTP and other desktop and web-application based automation tool, WebDriver has also capability to interact with process of windows operating system. For this purpose WebDriver API has one class WindowsUtils that handle all kind of processes related to windows.

WindowsUtils class help in killing or closing any running instance of any program on Windows operating system.Suppose there is some script that have some dependency of Notepad and you want to kill all instance of notepad before running the script.It means we need to place one code that would kill the notepad instance and then script would start executing then for this purpose we will use one method tryToKillByName() by name in WindowsUtils class.

So our generic code would be like this

@Before
public void start()
{
WindowsUtils.tryToKillByName("notepad.exe");
driver = new FirefoxDriver();
driver.get("http://www.google.com");
}

tryToKillByName() function can kill any instance of program by its name and if some processes are coming in to way of script execution those are creating run time error then it really helps to proceed with plan B to kill the all running instance of process though the code.

This Class have many other functions that helps in changing/read the value of registry  and those are like

suppose you want to know what kind of operating system you are using then you can use this code

String operating_system_name = WindowsUtils.readStringRegistryValue
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows
NT/CurrentVersion/ProductName");
System.out.println(operating_system_name);

but to use this WindowsUtils we need to import the org.openqa.selenium.os.WindowsUtils class and if you are using IDE then things get more easy because one hit of CTRL + Space give a lot of option and it all depends upon us to select the kind of function that we need to choose for our specific action.

So have a good time with this WindowsUtils and learn and let me also know the same.

4 thoughts on “Handling Windows Processes Through WebDriver

  1. Hi Dwarika,

    When I tried the above code for RegistryValue, as soon as I hit run, suddenly “Obsolete Mathods on the stach” popup box appears.
    Inside it, it says “This package.class at localhost:49185 contains obsolete methods”

    Please help me in seeing this code is working.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>