Can selenium automate desktop applications?

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:
4.0.0 WiniumDemo WiniumDemo 0.0.1-SNAPSHOT com.github.2gis.winium winium-webdriver 0.1.0-1

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[“//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[“//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.

Automation testing has become the need of an hour. Almost every industry has realized the importance of test automation. Therefore organizations are relying on a variety of automation tools to automate their web-based application, mobile application, and desktop application. However, whenever it comes to automation testing tool that is always preferred by industry experts is selenium. But mostly this tool is used for automating web-based applications and can also be used for automating mobile applications with the help of its extension called selendroid. But can this tool be used for automating desktop applications? Let’s find out in this article.

What is a desktop application?

It is a stand-alone application or commonly known as a client-server application that runs on a desktop’s or laptop’s computer. It uses computer resources such as hard disk and memory to run the program. It works on a client-server architecture and where multiple requests are sent to a centralized server that sends services and resources against the request.

How to automate desktop applications using selenium?

Desktop applications cannot be automated by using selenium because this tool cannot recognize the objects or the web elements on the desktop application. However, there is are few tools such as Winium, AutoIT, TestComplete, WinAppDriver, Sikuli, etc. that can be used for automating the desktop application. 

Out of all the available options, Winium is the ideal option as it is built on selenium and is an open-source automation framework used for interacting with windows applications. Any desktop application developed on WPF [Windows Presentation Foundation] or Winforms can be automated using this framework. Using Winium is similar to using selenium as the API of Winium resembles that of Selenium.

Winium = Win [Windows-based Application] + Selenium

Winium allows testers to code in any language as it supports multiple languages such as C#, Java, Python, etc. Testers can use inspect.exe or UISpy is used to identify the objects in the desktop applications. This tool supports multiple testing frameworks like TestNg, Junit, Pyunit, Nunit

What are some of the prerequisites for Winum?

  • Microsoft .NET Framework 4.5.1
  • Desktop.Driver.exe
  • Dependencies that can be downloaded using the Maven File

Why businesses should leverage Winium?

Though there are various open-source test automation tools available in the market for automating desktop applications such as UFT, AutoIT, and Sikuli. However, deciding the right tool for the desktop app might be a difficult task for teams as every tool comes with its pros and cons. 

For example, AutoIT requires extensive learning and hands-on expertise as it is based on a unique coding language. Similarly, Sikuli requires teams to maintain various screenshots to write the automation script, which is a tedious task.

If you are familiar with Selenium or any other programming language, Winium is the ideal tool for desktop application automation. Firstly it is free and open-source and secondly, just like in selenium you use Firebug and Firepath to identify the element locators, you need to inspect.exe or UISpy to identify the element locators in Windows applications. 

To summarize everything, it is clear that the selenium web driver cannot be used for automating desktop applications. However, one can use selenium + window-based tools i.e. Winium for automating desktop or windows applications. Though there are other tools also available in market such as  AutoIT, TestComplete, Sikuli, etc. that can also be used but winium is considered as an ideal choice for those who are completely comfortable with selenium as this tool share the same functionality as selenium.  Leverage automation testing from a next-gen QA and software testing services provider to get high-quality software.

Video liên quan

Chủ Đề