Test Automation for Windows Desktop Applications using Winium

Share

Introduction

Automation plays a significant role to achieve product quality success and deliver it on time. You need to follow this specific path: initially invent a solution to test problems, discover a long-term and cost-effective solution, and make a comprehensive coverage against requirements.

You can  successfully carry out test automation for when you have a requirement for automating Windows Desktop Application. Initially, if you think of using Sikuli for the automation and feel the need to take the screenshot of all the objects, you will realize that it’s very difficult to manage the dynamic objects in the application. But with the Winium tool, there no need to use a screenshot of the objects; you can use as Selenium based locators like name, id and class. Winium helps you to automate faster and deliver on time.

You have Selenium WebDriver for testing of web apps and Appium for testing of iOS and Android apps. Winium is introduced to testing of Windows apps and it is a Selenium-based tool. You are able to write tests with your favorite Dev tools using any WebDriver-compatible language such as Java, JavaScript with Node.js, PHP, Python, Ruby, C with the Selenium WebDriver API and language-specific client libraries.

There are different automation tools and frameworks which are available for windows applications like Sikuli, AutoIt, Winium etc. These tools used for desktop application (windows) automation for testing have their pros and cons.

Among all of them, Winium is the most convenient and popular automation framework for desktop application. Winium is Selenium Remote WebDriver implementation for automated testing of Windows application, based on WinFroms and WPF platforms. Following are the details of a POC with Winium:

Prerequisites of Winium:

  • 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, is the identification of notepad.exe for automation.

    How do 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();

    Conclusion

    Automation initiatives enable enterprises to create a wave of digital transformation. With Winium, automation is simplified for Windows Desktop Application. Winium is undoubtedly, the most handy tool for automating windows application as it is Selenium based. People who are much familiar with Selenium based commands find it quite easy to work with Winium. It is also, pretty fast compared to other tools. Open source applications enable you to modify the framework in any way that you want. There are unlimited possibilities to enhance the script with Winium.

    By,
    Sanoj S
    Test Architect, RapidValue

    ONE COMMENT

    1. Kavitha J says:

      Hi,

      I would need your help.I am currently automating our desktop application using winium.
      I am using UISPy tool to capture the objects of my desktop application.
      I came across a situation where there is a properties panel which has different attributes based on tree item.
      I am able to access the properties panel window when I try for the first time,The window (UISpy) doesnt get automatically refreshed when I select a different tree element.On refreshing the windows , I am able to view the current attributes of the selected tree element.
      But I dont find a way to refresh the windows element from my python code.
      Could you please help ?

      Thank you!

    LEAVE A COMMENT

    How can we help you?