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 !

Selenium – Sikuli

IntegrateSikuliWithSelenium

Automate anything you see using Sikuli (an interesting GUI automation tool). As said Sikuli automates anything you see on-screen using the image recognition method to identify GUI elements on the screen.

Most of the automation testing tools will not support flash object automation (E.g. Selenium). Sikuli provides extensive support to automate flash objects. And also Sikuli provides support to automate desktop applications.

Selenium-Sikuli combination provides more support for the automation engineers. Most of the time in automation for web application, we may face to identify the elements from the web UI or the locators values are getting wrong. In such situation Sikuli comes in picture, Sikuli allows to automate GUI interaction by using images of elements instead of using the xpath, id, linktext, classes etc.,

Important steps to proceed

  1. Create a Maven project in Eclipse.
  2. Add following dependencies in pom.xml file:
    1. selenium-server
    2. selenium-java
    3. sikulixapi
    4. testng
  3. Create TestNG classes.
  4. Create WebDriver object to start driver session and load website.
  5. Create a folder inside src/main/resources and store the images of web elements inside that folder.
  6. Add the sikuli scripts to perform operations on the elements (like click, type, wait, doubleClick).
  7. Create a testng.xml file for the created TestNG class and execute testng.xml.
  8. Observe the results on executions.

Below is the sample Selenium-Sikuli Maven project structure:

Capturesefsfsf

Common Sikuli Actions

Create an object for Screen class, say Screen s = new Screen(); and perform various actions:

  1. click :  s.click(<path to image>); – helps to click on web element using its image.
  2. rightClick : s.rightClick(<path to image>); – helps to right-click on web element using its image.
  3. doubleClick : s.doubleClick(<path to image>); – helps to double-click on web element that displaying in the view.
  4. find : s.find(<path to image>); –  helps to locate a web element using the image of particular web objects.
  5. exists : s.exists(<path to image>); – helps to check the web element is present on the view.
  6. type : s.type(<path to image>, <input value to edit-box>); – helps to enter value to an input field.
  7. hover : s.hover(<path to image>); – helps to mouse hover a web element in the web page.
  8. wait : s.wait(<path to image>); – helps to wait for a web element on the page until it get displayed. There another method for wait is with timeout value, it looks like s.wait(<path to image>, <timeout in seconds>);
  9. dragDrop : s.dragDrop(<source image path>, <target image path>); – helps to drag an object(source image object) from one location and drop that object over other object (target image object) at target location.

Click here to get sample Selenium – Sikuli POC project and explore more. If you have any difficulty to get the POC project, please feel free to comment here.