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. It 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.
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.
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(); } }
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.
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
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
But how do you deploy and remote execute it for desktop testing? With CodedUI, we can remote execute via test agent and as Winium is a wrapper around codedui (sort of via Microsoft UI Automation library) then shouldn’t it have the same capability?
Without a means to remote execute from our build server (TFS) it is sort of worthless.
what you want to deploy and what do you mean by remote execute ?
If you are asking about CI and central repo .It is possible
Winium is more flexible and easy compared to coded UI in terms of coding,reporting and in speed of test execution
There is no record option available in winium like we have in coded UI ,so its purely for folks who likes coding.
How did ur program run… I think u have not even tested this program. Because the declaration says driver and the implementation uses diver.
From your comment ,I think you do not have basics of programming and your are lazy to explore
Hi, I’m unable to identify the element from the WinForm application. I’m using ..
driver.findElementByClassName(“”).click()
Thread.sleep(2000)
driver.findElementById(“”).click()
Thread.sleep(2000)
driver.findElementByName(“”).click()
Thread.sleep(2000)
Any suggestion.