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”.
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”
Thanks for the article. It would be more complete, if you add a Linux solution, too. 🙂
Thanks for this good article. Can you please add a Linux solution, too?
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.
Thank you for this query and to learn more about this query can you provide me more detail regarding to this so that i could come on some conclusion that what is the key problem