Handling Windows Processes Through Selenium WebDriver

Like QTP and other desktop and web-application based automation tool, WebDriver has capability to interact with process of windows operating system. Due to this complete post is going to teach you “Handling Windows Processes Through Selenium WebDriver”.

Handling Windows Processes Through WebDriver
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 I am pretty sure that you have learnt “Handling Windows Processes Through Selenium WebDriver”

Dwarika Dhish Mishra

My name is Dwarika Dhish Mishra, its just my name and I am trying to bring the worth of my name in to actions and wants to be the solution not the problem. I believe in spreading knowledge and happiness. More over I am fun loving person and like travelling a lot. By nature I am a tester and a solution maker. I believe in the tag line of http://ted.org “Idea worth spreading” . For the same, I have created this blog to bring more and more learning to tester fraternity through day to day learning in professional and personal life. All contents are the part of my learning and so are available for all..So please spread the contents as much as you can at your end so that it could reach to every needful people in testing fraternity. I am pretty happy that more and more people are showing interest to become the part your Abode QA blog and I think this is good sign for us all because more and more content would be before you to read and to cherish. You may write or call me at my Email id: dwarika1987@gmail.com Cell: 9999978609

You may also like...

4 Responses

  1. semodesign says:

    Thanks for the article. It would be more complete, if you add a Linux solution, too. 🙂

  2. semodesign says:

    Thanks for this good article. Can you please add a Linux solution, too?

  3. Chiranjeevi says:

    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

This site uses Akismet to reduce spam. Learn how your comment data is processed.