Originally, Selenium WebDriver meant for automation testing of web UI or simply GUI testing. Later on, different developers came and further implemented the WebDriver to achieve different purposes in testing for different applications and platforms. For example, Appium for Mobile Testing, Provar for Salesforce Testing and now Winium Tool for Desktop application testing. Today we are going to discuss the end to end way to perform desktop application testing by using Selenium and Winium tool.
Recommended Reading: How to find Mobile Elements through Chrome casting?
What is Winium Tool?
Winium is an opensource tool that uses Selenium to automate Windows application. It supports both Windows desktop and Windows mobile applications. It uses WinForms & WPF GUI library to identify elements.
What is WinForms & WPF?
WinForms (Windows Forms) is a platform to write client applications for PC, tablets, and mobiles. It is a GUI library inside Microsoft .Net Framework.
WPF stands for Windows Presentation Foundation. It is GUI sub-systems like WinForms, used to render UI in Windows application.
What are the programming languages supported by Winium Tool?
It supports all the language which Selenium WebDriver supports.
Pre-Requisites
You need to fulfill the following pre-requisites before using Winium for the automation of windows desktop applications.
- Microsoft .Net Framework
- Winium Elements Desktop Jar file (or its dependency)
- Winium Desktop Driver exe file as server setup
- GUI Elements identifier tool
Microsoft .Net Framework acts as a catalyst for the GUI elements identifier tool, without it GUI identifier tools won’t work.
How to download the Winium Elements Desktop Jar file?
You can either use Jar file in your project or simply declare its dependency inside pom.xml.
Click here to download the jar file from the Maven repository site.
Alternatively, you can paste below dependency in pom.xml.
<!-- https://mvnrepository.com/artifact/com.github.2gis.winium/winium-elements-desktop --> <dependency> <groupId>com.github.2gis.winium</groupId> <artifactId>winium-elements-desktop</artifactId> <version>0.2.0-1</version> </dependency>
How to download Winium Desktop Driver exe file?
Go to the official Selenium download page and Look for the Third Party driver’s list. Click on Winium.Desktop link to download the exe file. Click here to navigate to the download page.
Or you can directly download from the release page @ GitHub -> Click here to download the driver.
How to install a GUI element identifier tool?
This is used to identify the desktop elements to perform the operations.
Click here to navigate to the GUI inspector repository.
You can download any one of them. It has the following GUI inspector tool:
- UISpy.exe
- AccEvent.exe
- Inspect.exe
- ViewWizard.exe
- AccExplorer32.exe
- SPYXX.exe
- WSEdit.exe
- Swapy-ob-0.4.3.exe
I am using UISpy.
DesktopOptions for Winium Tool
DesktopOptions is nothing but the capability definition. We have ChromeOptions, FirefoxOptions, etc; similarly, for Winium we have DesktopOptions to set the capabilities for Desktop applications.
Here is the sample code block:
DesktopOptions dop = new DesktopOptions(); dop.setApplicationPath("Path_of_the_Application");
To know more about Winium Capabilities and its arguments -> Click Here.
How does Winium Tool work for Desktop Application Automation?
DesktopOptions sets properties for RemoteWebDriver; Further, Windows.Desktop.Driver listens the commands coming from JSONWireProtocol and sends the instructions to windows platforms.
How to use the Winium Tool for Automation Testing of Desktop Application using Selenium & Java?
Follow the given step by step procedure to perform the test automation of Desktop application with Winium.
Step# 1: Start Local Server
Go to the location where Winium.Desktop.Driver.exe file is downloaded. Start the server with a double click.
It turns up the server at port 9999 locally; which receives commands from JSONWireProtocol.
Step# 2: Winium Element Desktop Jar File Implementation
Next, Open Eclipse and Add Winium Element Desktop jar file as an external dependency. Otherwise, you can declare the dependency directly in pom.xml.
Step# 3: Identify Desktop Elements using UISpy
Open UISpy and start inspecting desktop elements. On its launch, it displays elements of all the opened applications. See image below:
Step# 4: Write the program
The following program launches the application and gets the Name of the attribute and further clicks on New project.
package Test; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.winium.DesktopOptions; import org.openqa.selenium.winium.WiniumDriver; import com.itextpdf.text.log.SysoCounter; public class DesktopTestingDemo { public static void main(String[] args) throws MalformedURLException, InterruptedException { DesktopOptions dop = new DesktopOptions(); dop.setApplicationPath("C:\\Users\\Public\\Desktop\\Wondershare Filmora9.lnk"); URL remoteAddress = new URL("https://localhost:9999"); WebDriver driver = new WiniumDriver(remoteAddress, dop); System.out.println("Launched"); Thread.sleep(10000); System.out.println(driver.findElement(By.name("New Project")).getAttribute("Name")); Thread.sleep(5000); driver.findElement(By.name("New Project")).click(); Thread.sleep(5000); driver.quit(); } }
Console Output
This was all about the test automation of desktop applications using Winium. You can post your queries in comment below