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.

About these ads

One thought on “Handling Windows Processes Through WebDriver

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s