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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | </ 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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
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
No comments:
Post a Comment