Test Automation for Windows Desktop Applications using Winium

Share

Winium – Making Test Automation Faster & Better

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 to 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();

    Key Winnium Pointers to Consider

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

    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.

    If you want to learn more about our testing and test automation services and solutions, please

    contact us here

    By,
    Sanoj S
    Test Architect, RapidValue

    6 COMMENTS

    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!

    2. Shikha says:

      Can winium support remote desktop application automation. My application is on server which need to be automated.

      Please provide the link for the same.

    3. Sanoj says:

      @Shikha, Winium is a traditional concept, latest Appium support to automation desktop applications in both Windows and MAC. You need to set the desired capabilities for that,

      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability(“app”, “YOUR_APPLICATION_PATH”);
      capabilities.setCapability(“platformName”, “Windows”);//For MAC desktop the value should be Mac
      capabilities.setCapability(“deviceName”, “WindowsPC”);//For MAC desktop the value should be Mac
      driver = new WindowsDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities);

      In your case, the Appium server should run in the remote system where the application installed. You need to start the appium server in the remote system with that system’s IP. The same IP you need to mention in the URL section instead of 0.0.0.0

    4. Vishaka says:

      Hi,
      Doing my desktop automation using Winium. The automation works fine until there is no disturbance like mouse clicking/keyboard pressing. It doesnt work when I minimize the remote server or do anything using the mouse. Please provide possible solution to overcome this. Thanks.

    5. Sanoj says:

      Hi Vishaka,

      As per the Winium or WinAppDriver concept, they are using inspect UI tree mechanism to traverse through elements. So the application should run the foreground. They strict to UI visibility means UI components should be in the foreground not like Web application interactions. You can extend your screen and try to run script on that screen to avoid the interruptions or you can set a server system only for execution purposes.

      Thanks,
      Sanoj

    6. Vishaka says:

      Hi Sanoj,
      Thank you for the elaborate answer. Does that mean, it is not possible to automate desktop application with the desktop being inactive(or we cannot do any other operations in that machine?)

    Please Share Your Thoughts & Comments Below.

    How can we help you?