OpenSource For You

Winium: A Selenium Based Windows Automation Tool

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

-

Security

We all know about Selenium, which is used to automate Web applicatio­ns. Winium is the tool that is built on Selenium to interact with Windows applicatio­ns. It is free and open source. Using it is similar to working with Selenium; it’s just that it is used for Windows desktop applicatio­ns.

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

Using Winium

Just as there are some prerequisi­tes for Web app automation using Selenium, there are some prerequisi­tes for working with Winium. We need the following: Microsoft .NET Framework 4.5.1 Winium.Desktop.Driver.exe

Some other dependenci­es 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:schemaLoca­tion=”http://maven.apache.org/POM/4.0.0 http:// maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersi­on>4.0.0</modelVersi­on> <groupId>WiniumDemo</groupId> <artifactId>WiniumDemo</artifactId> <version>0.0.1-SNAPSHOT</version>

<dependenci­es>

<dependency> <groupId>com.github.2gis.winium</groupId> <artifactId>winium-webdriver</artifactId> <version>0.1.0-1</version>

</dependency>

</dependenci­es> </project>

Once we have the above requiremen­ts 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.

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:

DesktopOpt­ions option = new DesktopOpt­ions(); option.setApplica­tionPath(“C:\\Windows\\System32\\calc.exe”);

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

I have created the object of DesktopOpt­ions, which will help us to point the applicatio­n we are automating (I have used the calculator applicatio­n for explaining this).

By initiating the Winium driver using the Winiumdriv­er class, we are passing the Winium server URL and the path of our desktop applicatio­n 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 initialisi­ng the Winium driver is similar to that of the Selenium driver, as we see with reference to Selenium.

WebDriver driver = new FirefoxDri­ver();

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

driver.findElemen­t(By.name(“Seven”)).click(); driver.findElemen­t(By.name(“Plus”)).click(); driver.findElemen­t(By.name(“Eight”)).click(); driver.findElemen­t(By.name(“Equals”)).click(); Thread.sleep(5000);

String output = driver.findElemen­t(By. id(“Calculator­Results”)).getAttribu­te(“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.MalformedU­RLExceptio­n; import java.net.URL;

import org.openqa.selenium.By;

import org.openqa.selenium.winium.DesktopOpt­ions; import org.openqa.selenium.winium.WiniumDriv­er;

public class MyFirstTes­tCase {

public static void main(String[] args) throws MalformedU­RLExceptio­n, Interrupte­dException {

DesktopOpt­ions option = new DesktopOpt­ions();

option.setApplica­tionPath(“C:\\Windows\\System32\\ calc.exe”);

WiniumDriv­er driver = new WiniumDriv­er(new URL(“http://localhost:9999”), option); Thread.sleep(5000); driver.findElemen­t(By.name(“Seven”)).click(); driver.findElemen­t(By.name(“Plus”)).click(); driver.findElemen­t(By.name(“Eight”)).click(); driver.findElemen­t(By.name(“Equals”)).click(); Thread.sleep(5000);

String output = diver.findElemen­t(By. id(“Calculator­Results”)).getAttribu­te(“Name”); System.out.println(“Result after addition is: “+output);

When to use Winium

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

Reference

[1] https://github.com/2gis/Winium

By: N.R. Athmeeya

The author works as a Selenium automation developer at Dell EMC (EMC2). He has six years of experience in automation testing.

 ??  ??
 ??  ??
 ??  ?? Figure 1: Firepath and Firebug being used to identify the UI element locator for selenium
Figure 1: Firepath and Firebug being used to identify the UI element locator for selenium
 ??  ?? Figure 2: UISpy showing the properties of the button ‘seven’ of the calculator used to find the element properties for Winium
Figure 2: UISpy showing the properties of the button ‘seven’ of the calculator used to find the element properties for Winium
 ??  ??

Newspapers in English

Newspapers from India