Automation for Windows Desktop Applications

AAEAAQAAAAAAAAuhAAAAJDg0MTllY2JlLWJlYjUtNDllOC05M2NmLWMxNzkxMzczYjU2YQ

      There are lots of different automation tools and frameworks are available for windows applications like – Sikuli, AutoIt, Winium etc. I have gone through all of them for desktop application (windows) automation for testing. All of them have different pros and cons.

        Among all of them I found Winium the most easy and handy automation framework for desktop application. Winium is Selenium Remote WebDriver implementation for automated testing of Windows application based on WinFroms and WPF platforms. I have done a POC with Winium. Following are the details:

Prerequisites:

  • Install Microsoft .NET Framework 4.5.1
  • Create Maven Project and add following dependencies in pom.xml file
    • selenium-java
    • selenium-server
    • winium-elements-desktop
    • winium-webdriver

Here I identified notepad.exe for automation.

How can we create a Winium Driver session?

WebDriver driver = null;
String notepadApplicationPath = “C:\\Windows\\System32\\notepad.exe”;
String winiumDriverPath = “D:\\SeleniumDrivers\\Winium.Desktop.Driver.exe”;// To stop winium desktop driver before start another session
Process process = Runtime.getRuntime().exec(“taskkill /F /IM Winium.Desktop.Driver.exe”);
process.waitFor();
process.destroy();
DesktopOptions options = new DesktopOptions(); // Initiate Winium Desktop Options
options.setApplicationPath(notepadApplicationPath); // Set notepad application path
WiniumDriverService service = new WiniumDriverService.Builder().usingDriverExecutable(new File(winiumDriverPath)).usingPort(9999).withVerbose(true).withSilent(false).buildDesktopService();
service.start(); // Build and Start a Winium Driver service
Thread.sleep(5000);
driver = new WiniumDriver(service, options); // Start a winium driver
Thread.sleep(10000);

Once you get the driver you can start your automation scripts like selenium scripting,

Thread.sleep(5000);
driver.findElement(By.name(“Format”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Font…”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Bold”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“OK”)).click();
Thread.sleep(1000);
driver.findElement(By.className(“Edit”)).sendKeys(“Welcome to Winium”);
Thread.sleep(1000);
driver.findElement(By.name(“File”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Save”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“File name:”)).sendKeys(“NewFile”);
Thread.sleep(1000);
driver.findElement(By.name(“Save”)).click();
Thread.sleep(1000);
driver.findElement(By.name(“Close”)).click();

NOTE: 

Process process = Runtime.getRuntime().exec(“taskkill /F /IM Winium.Desktop.Driver.exe”);
process.waitFor();
process.destroy();

make it perfect !