Windows application (Desktop) automation with Winium

There are lots of different automation tools and frameworks are available for windows applications (mainly for desktop application ) like – Sikuli, AutoIt, CodedUI, Winium etc. I have gone through all of them for desktop application (windows) automation for testing. All of them have different advantages and disadvantages.

Among all of them i found ‘winium’ the most easy and handy automation framework for desktop application . It’s completely my personal opinion.In this post i am going to describe the following things-

1.What is winium

2.Why it is better than other tools (according to me)

3.How to set up the whole environment for using winium

4.Some example

Winium

Winium is an automation framework for windows platform. It is free, opensource and most importantly it is selenium based.

Why Winium: 

  • With winium we can write our test with any language that’s compatible with webdriver such as – Java, Objective-C, JavaScript with Node.js (in promise, callback or generator flavors), PHP, Python, Ruby, C#, Clojure, or Perl with the Selenium WebDriver API and language-specific client libraries.
  • we can use any testing framework with it
  • Supported platforms – Windows Desktop (WPF, WinForms) Apps,Windows Store or Universal Apps for Windows Phone,Windows Phone Silverlight Apps

Here our main focus is winium for desktop

Winium.Desktop is Selenium Remote WebDriver implementation for automated testing of Windows application based on WinFroms and WPF platforms.

Supported Platforms

  • WinForms
  • WPF

Requirements:

  • Microsoft .NET Framework 4.5.1

Steps to setup the environment:

  • First we need to set up .NET Framework 4.5.1 in our system
  • Then go to the following address to download winium.desktop.exe – https://github.com/2gis/Winium.Desktop/releases
  • All other libraries we are going to download through maven, below i am giving my maven dependencies
</pre>
<pre><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="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>com.autiomation.winium</groupId>
    <artifactId>com.autiomation.winium</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.2gis.winium</groupId>
            <artifactId>winium-elements-desktop</artifactId>
            <version>0.2.0-1</version>
        </dependency>

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


        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.15</version>
        </dependency>


    </dependencies>

</project></pre>
<pre>

To initiate the winium driver


public WiniumDriver setupEnvironment() throws IOException {

    String outlookApplicationPath = "C:\\ProgramfileS|\...\..\outlook.exe";
    String winiumDriverPath = "C:\Progra...\..\winium.desktop.exe";

    options = new DesktopOptions(); //Initiate Winium Desktop Options
    options.setApplicationPath(outlookApplicationPath); //Set outlook application path

    File drivePath = new File(winiumDriverPath); //Set winium driver path

    service = new WiniumDriverService.Builder().usingDriverExecutable(drivePath).usingPort(9999).withVerbose(true).withSilent(false).buildDesktopService();
    service.start(); //Build and Start a Winium Driver service
    driver = new WiniumDriver(service, options); //Start a winium driver

    return driver;

}

This block of code will create the driver to communicate with our application. Rest of the things are like automating a web application with selenium. We are going to use basic selenium commands like “findElementBy.sendKeys()” or “findElementBy.click()” etc.

Example – adding two number with the calculator application in windows


public void addNumberTest() throws InterruptedException {

    Thread.sleep(5000);
    WebElement calcFrame = driver.findElement(By.className("CalcFrame"));
    WebElement menu = driver.findElement(By.id("MenuBar"));
    WebElement viewMenu = menu.findElement(By.name("View"));
    viewMenu.click();
    viewMenu.findElement(By.name("Scientific")).click();
    Thread.sleep(2000);
    calcFrame.findElement(By.id("132")).click();
    Thread.sleep(2000);
    calcFrame.findElement(By.id("93")).click();
    Thread.sleep(2000);
    calcFrame.findElement(By.id("134")).click();
    Thread.sleep(2000);
    calcFrame.findElement(By.id("121")).click();
    Thread.sleep(2000);
}

To find the element properties of a windows application we will use “Inspect.exe” which is available by default in windows if not just download it.It gives all the properties of a desktop application to control it

153493

Winium is much handy tools for automating windows application as it is selenium based. We are very much familiar with selenium based commands so  it is very easy for us to work with winium.And it is pretty fast comparing to other tools i think.

Resource links – https://github.com/2gis/Winium

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: