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>

    4.0.0

    com.autiomation.winium
    com.autiomation.winium
    1.0-SNAPSHOT
    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.6
                    1.6
                
            
        
    

    

        
            junit
            junit
            3.8.1
            test
        

        
            com.github.2gis.winium
            winium-elements-desktop
            0.2.0-1
        

        
            com.github.2gis.winium
            winium-webdriver
            0.1.0-1
        

        
            org.testng
            testng
            6.11
        

        
            org.apache.poi
            poi-ooxml
            3.15
        

    

</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

10 thoughts on “Windows application (Desktop) automation with Winium

Add yours

    1. You can always click on scroll down arrow or you can execute script for mouse scroll event by pixel resolution.Can u give me a screenshot of your application page where you need to perform the scroll operation?

      1. i am trying to drag n drop
        my code is

        element=driver.findElementByClassName(“Thumb”);
        Actions ac= new Actions (driver);
        ac.dragAndDropBy(element, 0, 20).build().perform();

        Exception that I am getting is

        FAILED: PatientPlan1Pass
        org.openqa.selenium.UnsupportedCommandException: ‘mouseDown’ is not valid or implemented command. (WARNING: The server did not provide any stacktrace information)
        Command duration or timeout: 5 milliseconds

        Not sure how to attach screenshot here

  1. IsDisplayed() takes more than 10 minutes to return when the element is NOT present.
    Below is a sample code. If the element is present it works perfectly. But if the element is NOT present it takes almost 10 minutes to show ‘NoSuchElementException ‘ and then comes to the Catch block.
    The Default Search Time needs to be reduced in Winium.
    public void ServerConflict() throws Exception {
    try {
    WPF1.findElement(ConflictYesBtn).isDisplayed();
    WPF1.findElement(ConflictYesBtn).click();
    System.out.println(“Button Present”);
    }
    catch (NoSuchElementException e)
    {
    System.out.println(“Button NOT Present”);
    }
    }
    Please suggest

      1. This is the code that I’m using for WPF, The similar code works in Web but not in WPF Winium

        protected By ConflictYesBtn = By.id(“6”);

        if(isWPFElementPresent(ConflictYesBtn)==true)
        {
        System.out.println(“Element Present”);
        }
        else
        {
        System.out.println(“Element NOT Present”);
        }

        public boolean isWPFElementPresent(By element) {
        boolean status = false;

        try {
        WPF1.findElement(element).isDisplayed();
        status = true;
        } catch (NoSuchElementException e) {
        status = false;
        }

        return status;
        }

      2. You can try driver.manage.timeout() method if that doesn’t reduce the time u can try finding the conflictbtn by joining multiple attribute. What I meant is try to narrow down the DOM path for conflictBtn.

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: