Winium: A Selenium Based Windows Automation Tool

4
8427
Advertisement

Winium is a Selenium based tool for testing and automating desktop applications on the Windows desktop. It is easy to use for those who are familiar with Selenium.

We all know about Selenium, which is used to automate Web applications. Winium is the tool that is built on Selenium to interact with Windows applications. It is free and open source.

Using it is similar to working with Selenium; it’s just that it is used for Windows desktop applications.

Advertisement

Just as we use Firebug and Firepath to identify the element locators for Web applications in Selenium, we are going to use tools such as inspect.exe or UISpy to identify the element locators in Windows applications.

Using Winium

Just as there are some prerequisites for Web app automation using Selenium, there are some prerequisites for working with Winium. We need the following:

  • Microsoft .NET Framework 4.5.1
  • Winium.Desktop.Driver.exe
  • Some other dependencies that are downloaded using the Maven file, as mentioned in the POM file below:
<project xmls=”http://maven.apache.org/POM/4.0.0” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>

<modelVersion>4.0.0</modelVersion>

<groupId>WiniumDemo</groupId>

<artifactId>WiniumDemo</artifactId>

<version>0.0.1-SNAPSHOT</version>

<dependencies>

<dependency>

<groupId>com.github.2gis.winium</groupId>

<artifactId>winium-webdriver</artifactId>

<version>0.1.0-1</version>

</dependency>

</dependencies>

</project>

Once we have the above requirements set up on the desktop, let’s begin initiating the Winium driver, which is similar to the procedure for initiating the Selenium driver, as shown below.

Figure 1: Firepath and Firebug being used to identify the UI element locator for selenium

We can write our test in any language that’s compatible with WebDriver such as Java, Objective-C, JavaScript with Node.js PHP, Python, Ruby, C#, Perl with the Selenium WebDriver API and language-specific client libraries. I have written it in Java, as shown below:

DesktopOptions option = new DesktopOptions();

option.setApplicationPath(“C:\\Windows\\System32\\calc.exe”);

WiniumDriver driver = new WiniumDriver(new URL(“http://localhost:9999”), option);

I have created the object of DesktopOptions, which will help us to point the application we are automating (I have used the calculator application for explaining this).

By initiating the Winium driver using the Winiumdriver class, we are passing the Winium server URL and the path of our desktop application on which automation is intended to be carried out.

The server URL is obtained by clicking on the Winium.desktop.driver.exe that was downloaded.

The process of initialising the Winium driver is similar to that of the Selenium driver, as we see with reference to Selenium.

WebDriver driver = new FirefoxDriver();

Now we are all set to write some code to interact with the desktop application. I have used it to open the calculator and to perform the task of adding seven and eight, and to capture the result.

driver.findElement(By.name(“Seven”)).click();

driver.findElement(By.name(“Plus”)).click();

driver.findElement(By.name(“Eight”)).click();

driver.findElement(By.name(“Equals”)).click();

Thread.sleep(5000);

String output = driver.findElement(By.id(“CalculatorResults”)).getAttribute(“Name”);

System.out.println(“Result after addition is: “+output);

We can identify the element using the name, ID and xpath, just as we do using Firepath in Selenium.

Please refer the complete working code mentioned below:

package com.winium.demo;

import java.net.MalformedURLException;

import java.net.URL;

import org.openqa.selenium.By;

import org.openqa.selenium.winium.DesktopOptions;

import org.openqa.selenium.winium.WiniumDriver;

public class MyFirstTestCase {

public static void main(String[] args) throws MalformedURLException, InterruptedException {

DesktopOptions option = new DesktopOptions();

option.setApplicationPath(“C:\\Windows\\System32\\calc.exe”);

WiniumDriver driver = new WiniumDriver(new URL(“http://localhost:9999”), option);

Thread.sleep(5000);

driver.findElement(By.name(“Seven”)).click();

driver.findElement(By.name(“Plus”)).click();

driver.findElement(By.name(“Eight”)).click();

driver.findElement(By.name(“Equals”)).click();

Thread.sleep(5000);

String output = diver.findElement(By.id(“CalculatorResults”)).getAttribute(“Name”);

System.out.println(“Result after addition is: “+output);

driver.quit();

}

}
Figure 2: UISpy showing the properties of the button ‘seven’ of the calculator used to find the element properties for winium

When to use Winium

Use Winium once you are familiar with Selenium and are in search of a tool to automate the Windows desktop application. Winium fits the bill as you are already aware of most of the functionality in Selenium. There are a few bugs in Winium right now and it is still undergoing a maturing process, just like Selenium once did.

Advertisement

4 COMMENTS

  1. It is more helpful for me especially and please let me inform if any other articles or information regarding winium tool.

    • There are no better articles/links available other than GitHub as it is not popular as selenium, but you can check out youtube videos. They are really informative and helpful

  2. Its good tool to use but there is further development going on to make it better. Last checkin (in GitHub) was in Dec’16.

    • Yes waiting for further improvements ,It can revolutionize desktop application’s automation. Being a freeware and opensource is a big win

LEAVE A REPLY

Please enter your comment!
Please enter your name here