Winium is a Automation framework for Windows Applications. It is a open source tool from 2GIS. Winium supports
We know that selenium supports only web applications. There are multiple other tools that we discussed in our previous blogs like AutoIT, Sikuli can be used to automate Windows based applications. But winium has the below advantages comparing to AutoIT and Sikuli.
Technically, Winium.Desktop is an http client. It implements JSWP protocol and uses Cruciatus to work with UI elements. Essentially, this is an implementation of WebDriver for Windows-based desktop applications. It uses regular Selenium bindings with Winium. Desktop in order to test Windows-based desktop applications.
Below are the features of Winium.
Below are commands that are supported by Winium.
Disadvantages:
Step 1:
Download the below jars
http://mvnrepository.com/artifact/com.github.2gis.winium/winium-elements-desktop/0.1.0-1
http://mvnrepository.com/artifact/com.github.2gis.winium/winium-elements-desktop/0.2.0-1
Along with these two jars you need to have selenium latest jar as well. You can get the latest selenium jar from the below path.
http://docs.seleniumhq.org/download/
Step 2:
Download Winium.Desktop.Driver.exe file from https://github.com/2gis/Winium.Desktop/releases (Latest). Extract the zip file
Step 3:
Run the Winium.Desktop.Driver.exe file (by double clicking the Winium. Desktop.Driver.exe file). So that a Winium desktop server will be started and running at port 9999.
Step 4:
Create a sample Java project and add the downloaded jars into the class path of the project and also TestNG Library. Now create a class and use the below code.
package com.src.Nainappa.test;
import java.io.IOException;
import java.net.URL;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
import org.testng.annotations.Test;
public class NotepadTest {
@Test
public void test() throws IOException{
DesktopOptions options= new DesktopOptions();
options.setApplicationPath("C:\\WINDOWS\\system32\\notepad.exe");
try{
WiniumDriver driver=new WiniumDriver(new URL("http://localhost:9999"),options);
driver.findElementByClassName("Edit").sendKeys("This is sample test");
driver.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Step 5:
Run this code as TestNG Method. It opens the notepad and enters the text on the note pad and also tries to close it.
If anybody is wondering how to get to know the properties of the elements, we have multiple ways.
1. Renorex offers free spy. We can download it from the below path and use it.
http://www.ranorex.com/test-automation-tools/ranorex-spy.html
2. The other way is White tool. You can download the entire tool from the below path.
https://github.com/TestStack/White
Extract the Zip file and you will see a file called UISpy.exe. This can also be used for spying on the elements.
We will see automating the Windows phone applications in our next post.
- Windows Desktop (WPF, WinForms) Apps
- Windows Store or Universal Apps for Windows Phone
- Windows Phone Silverlight Apps
But in this post we are going to discuss only about Winium for Desktop application automation.
- As discussed in our previous blogs, to use Auto IT, We have to use some windows bridge to access the methods in it. But Winium comes as Java API and also it is implemented on JSONWire protocal that is used by selenium.
- We can also write tests in any programming language that is supported by selenium.
- It supports wide magnitude of applications comparing to AutoIT.
Technically, Winium.Desktop is an http client. It implements JSWP protocol and uses Cruciatus to work with UI elements. Essentially, this is an implementation of WebDriver for Windows-based desktop applications. It uses regular Selenium bindings with Winium. Desktop in order to test Windows-based desktop applications.
Below are the features of Winium.
- Automates native windows desktop app(winforms, WPF, everyapp that uses MS accessibility)
- compatible with JSON wire protocal
- Full access to desktop and UI
- Protocal extensions for desktop specific elements
- We can write tests in any programming language which Selenium Web driver supports
Below are commands that are supported by Winium.
Command | Query |
---|---|
NewSession | POST /session |
FindElement | POST /session/:sessionId/element |
FindChildElement | POST /session/:sessionId/element/:id/element |
ClickElement | POST /session/:sessionId/element/:id/click |
SendKeysToElement | POST /session/:sessionId/element/:id/value |
GetElementText | GET /session/:sessionId/element/:id/text |
GetElementAttribute | GET /session/:sessionId/element/:id/attribute/:name |
Quit | DELETE /session/:sessionId |
ClearElement | POST /session/:sessionId/element/:id/clear |
Close | DELETE /session/:sessionId/window |
ElementEquals | GET /session/:sessionId/element/:id/equals/:other |
ExecuteScript | POST /session/:sessionId/execute |
FindChildElements | POST /session/:sessionId/element/:id/elements |
FindElements | POST /session/:sessionId/elements |
GetActiveElement | POST /session/:sessionId/element/active |
GetElementSize | GET /session/:sessionId/element/:id/size |
ImplicitlyWait | POST /session/:sessionId/timeouts/implicit_wait |
IsElementDisplayed | GET /session/:sessionId/element/:id/displayed |
IsElementEnabled | GET /session/:sessionId/element/:id/enabled |
IsElementSelected | GET /session/:sessionId/element/:id/selected |
MouseClick | POST /session/:sessionId/click |
MouseDoubleClick | POST /session/:sessionId/doubleclick |
MouseMoveTo | POST /session/:sessionId/moveto |
Screenshot | GET /session/:sessionId/screenshot |
SendKeysToActiveElement | POST /session/:sessionId/keys |
Status | GET /status |
SubmitElement | POST /session/:sessionId/element/:id/submit |
Disadvantages:
- It uses real mouse and key board events, i.e You can't run more than one session on same machine, or use mouse while tests are running.
- If the app runs in the background and remains running there, then it will not work appropriately.
- It is sometimes difficult to get the text from component that displays the output. Then you receive the error message: NO Text property. The reason is probably that this type of component is defined as Image.
Step 1:
Download the below jars
http://mvnrepository.com/artifact/com.github.2gis.winium/winium-elements-desktop/0.1.0-1
http://mvnrepository.com/artifact/com.github.2gis.winium/winium-elements-desktop/0.2.0-1
Along with these two jars you need to have selenium latest jar as well. You can get the latest selenium jar from the below path.
http://docs.seleniumhq.org/download/
Step 2:
Download Winium.Desktop.Driver.exe file from https://github.com/2gis/Winium.Desktop/releases (Latest). Extract the zip file
Step 3:
Run the Winium.Desktop.Driver.exe file (by double clicking the Winium. Desktop.Driver.exe file). So that a Winium desktop server will be started and running at port 9999.
Step 4:
Create a sample Java project and add the downloaded jars into the class path of the project and also TestNG Library. Now create a class and use the below code.
package com.src.Nainappa.test;
import java.io.IOException;
import java.net.URL;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
import org.testng.annotations.Test;
public class NotepadTest {
@Test
public void test() throws IOException{
DesktopOptions options= new DesktopOptions();
options.setApplicationPath("C:\\WINDOWS\\system32\\notepad.exe");
try{
WiniumDriver driver=new WiniumDriver(new URL("http://localhost:9999"),options);
driver.findElementByClassName("Edit").sendKeys("This is sample test");
driver.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Step 5:
Run this code as TestNG Method. It opens the notepad and enters the text on the note pad and also tries to close it.
If anybody is wondering how to get to know the properties of the elements, we have multiple ways.
1. Renorex offers free spy. We can download it from the below path and use it.
http://www.ranorex.com/test-automation-tools/ranorex-spy.html
2. The other way is White tool. You can download the entire tool from the below path.
https://github.com/TestStack/White
Extract the Zip file and you will see a file called UISpy.exe. This can also be used for spying on the elements.
We will see automating the Windows phone applications in our next post.
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
ReplyDeleteIs displayed when i run my program.
Kindly help me with solution
driver=new WiniumDriver("http://localhost:9999", options.toCapabilities());
DeleteDo i need do some changes in Host file ??
Thanks for the info sir .But It is not allowing m e to import WiniumDriver .So If you can tell me how to resolve this issue it would be better ..
ReplyDeleteCould you please post on automating the Windows phone applications. I am looking forward to it.
ReplyDeleteWhat if the program your after is not a .exe type? I'm trying to launch the Hyper-V Manager which requires navigation through Windows Control Panel and then clicking options presented there. Can this tool navigate the native windows desktop options or only apps that are .exe?
ReplyDelete@crhoads1024: This cannot handle the native desktop options. However you have other options such as Sikuli or AutoIT which you can try.
ReplyDeleteCould you please let me know how to get elements of Window Form?
ReplyDeleteDesktopOptions is not working, it is throwing compilation error and when i hover a mouse on DesktopOptions, eclpse does not show any required jars for that for importing. Where as it works for WiniumDriver. Please suggest me. I have imported both the jars.
ReplyDeleteDownload Winium WebDriver from https://mvnrepository.com/artifact/com.github.2gis.winium/winium-webdriver/0.1.0-1 and import to your project. it should work.
DeleteHow can I automate two desktop application?
ReplyDeleteIt worked for me I scripted for a demo calculator app and it worked.
ReplyDeleteThanks
please let me know how to scroll down so that an element becomes visible
ReplyDeleteCheck this link: https://github.com/2gis/Winium.Desktop/wiki/Supported-Commands
DeleteHi, I am trying to entire User ID on my application , but its giving Element not found.
ReplyDeleteCan some one help. Selenium+winium. Also my app is availale in remote system.
Can you give more specifics to your environment. Application type, OS type. And are you using any UI inspect tool for retrieving the locator ID.
DeleteI am using the Winium driver to work on my desktop application, Yes it is working for me but it has limitations so i have integrated another tool with selenium to tackle the issues.
ReplyDeleteHii, i am stuck at case where i want to switch control type, window to dialog. can anyone please help me out
ReplyDeleteThanks for the detailed description
ReplyDeleteHi, I am stuck at start. I added all the driver dependencies but still code is shouting that :
ReplyDeletedriver.close(); < Cannot find
driver.findElementByClassName() << Cannot find
Please help!!!!
package com.ubs.f2bwinium;
import java.io.IOException;
import java.net.URL;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
import org.testng.annotations.Test;
public class NotepadTest {
@Test
public void test() throws IOException{
DesktopOptions options= new DesktopOptions();
options.setApplicationPath("C:\\WINDOWS\\system32\\notepad.exe");
try{
WiniumDriver driver=new WiniumDriver(new URL("http://localhost:9999"),options);
driver.findElementByClassName("Edit").sendKeys("This is sample test");
driver.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
getting the same problem. Can anybody help ?
DeleteHi,
ReplyDeleteCan we automate java base developed applications by using winium
how can refer to an element which does not have any unique name,class,automationid.
ReplyDeleteHi there,
ReplyDeleteI am working on desktop automation using katalon and winium. initiated the driver in the first test case but the unable to use the same driver in the next test case.
when trying the use as below in the second test case
WiniumDriver driver;
DesktopOptions options = new DesktopOptions();
driver = new WiniumDriver(options)
facing the exception as [FATAL] Failed to start driver: System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address
driver initialisation in my first script is as follows
WiniumDriver driver = null
String appPath = ‘’
DesktopOptions option = new DesktopOptions()
option.setApplicationPath(appPath)
option.setDebugConnectToRunningApp(false)
option.setLaunchDelay(2)
driver = new WiniumDriver(new URL(‘http://localhost:9999’), option)
any leads???
~KA
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
ReplyDeleteBuild info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'WSAMZN-4QFICBPU', ip: 'XYZ', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '19.0.2'
Driver info: org.openqa.selenium.winium.WiniumDriver
Command: [null, newSession {capabilities=[Capabilities {}], desiredCapabilities=Capabilities {app: C:\Program Files\Java\jdk1....}}]
Capabilities {}
when i automaton for desktop application i got this error
ReplyDeleteorg.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'WSAMZN-4QFICBPU', ip: 'XYZ', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '19.0.2'
Driver info: org.openqa.selenium.winium.WiniumDriver
Command: [null, newSession {capabilities=[Capabilities {}], desiredCapabilities=Capabilities {app: C:\Program Files\Java\jdk1....}}]
Capabilities {}
My code is :
DesktopOptions option = new DesktopOptions();
option.setApplicationPath("C:\\Program Files\\Java\\jdk1.8.0_221\\bin\\Java.exe");
WiniumDriver driver= new WiniumDriver(new URL("http://localhost:9999"), option);