Winium: A Se­le­nium Based Win­dows Au­to­ma­tion Tool

Winium is a Se­le­nium based tool for test­ing and au­tomat­ing desk­top ap­pli­ca­tions on the Win­dows desk­top. It is easy to use for those who are fa­mil­iar with Se­le­nium.

OpenSource For You - - Contents -

Se­cu­rity

We all know about Se­le­nium, which is used to au­to­mate Web ap­pli­ca­tions. Winium is the tool that is built on Se­le­nium to in­ter­act with Win­dows ap­pli­ca­tions. It is free and open source. Us­ing it is sim­i­lar to work­ing with Se­le­nium; it’s just that it is used for Win­dows desk­top ap­pli­ca­tions.

Just as we use Fire­bug and Firepath to iden­tify the el­e­ment lo­ca­tors for Web ap­pli­ca­tions in Se­le­nium, we are go­ing to use tools such as in­spect.exe or UISpy to iden­tify the el­e­ment lo­ca­tors in Win­dows ap­pli­ca­tions.

Us­ing Winium

Just as there are some pre­req­ui­sites for Web app au­to­ma­tion us­ing Se­le­nium, there are some pre­req­ui­sites for work­ing with Winium. We need the fol­low­ing: Mi­crosoft .NET Frame­work 4.5.1 Winium.Desk­top.Driver.exe

Some other de­pen­den­cies that are down­loaded us­ing the Maven file, as men­tioned in the POM file below:

<project xmls=”http://maven.apache.org/POM/4.0.0” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-in­stance” xsi:schemaLo­ca­tion=”http://maven.apache.org/POM/4.0.0 http:// maven.apache.org/xsd/maven-4.0.0.xsd”> <mod­elVer­sion>4.0.0</mod­elVer­sion> <groupId>Wini­umDemo</groupId> <ar­ti­fac­tId>Wini­umDemo</ar­ti­fac­tId> <ver­sion>0.0.1-SNAP­SHOT</ver­sion>

<de­pen­den­cies>

<de­pen­dency> <groupId>com.github.2gis.winium</groupId> <ar­ti­fac­tId>winium-web­driver</ar­ti­fac­tId> <ver­sion>0.1.0-1</ver­sion>

</de­pen­dency>

</de­pen­den­cies> </project>

Once we have the above re­quire­ments set up on the desk­top, let’s be­gin ini­ti­at­ing the Winium driver, which is sim­i­lar to the pro­ce­dure for ini­ti­at­ing the Se­le­nium driver, as shown below.

We can write our test in any lan­guage that’s com­pat­i­ble with Web­Driver such as Java, Ob­jec­tive-C, JavaScript with Node.js PHP, Python, Ruby, C#, Perl with the Se­le­nium Web­Driver API and lan­guage-spe­cific client li­braries. I have writ­ten it in Java, as shown below:

Desk­topOp­tions op­tion = new Desk­topOp­tions(); op­tion.setAp­pli­ca­tionPath(“C:\\Win­dows\\Sys­tem32\\calc.exe”);

Wini­umDriver driver = new Wini­umDriver(new URL(“http:// lo­cal­host:9999”), op­tion);

I have cre­ated the ob­ject of Desk­topOp­tions, which will help us to point the ap­pli­ca­tion we are au­tomat­ing (I have used the cal­cu­la­tor ap­pli­ca­tion for ex­plain­ing this).

By ini­ti­at­ing the Winium driver us­ing the Wini­umdriver class, we are pass­ing the Winium server URL and the path of our desk­top ap­pli­ca­tion on which au­to­ma­tion is in­tended to be car­ried out.

The server URL is ob­tained by click­ing on the Winium. desk­top.driver.exe that was down­loaded.

The process of ini­tial­is­ing the Winium driver is sim­i­lar to that of the Se­le­nium driver, as we see with ref­er­ence to Se­le­nium.

Web­Driver driver = new Fire­foxDriver();

Now we are all set to write some code to in­ter­act with the desk­top ap­pli­ca­tion. I have used it to open the cal­cu­la­tor and to per­form the task of adding seven and eight, and to cap­ture the re­sult.

driver.find­Ele­ment(By.name(“Seven”)).click(); driver.find­Ele­ment(By.name(“Plus”)).click(); driver.find­Ele­ment(By.name(“Eight”)).click(); driver.find­Ele­ment(By.name(“Equals”)).click(); Thread.sleep(5000);

String out­put = driver.find­Ele­ment(By. id(“Cal­cu­la­torRe­sults”)).getAt­tribute(“Name”);

Sys­tem.out.println(“Re­sult af­ter ad­di­tion is: “+out­put);

We can iden­tify the el­e­ment us­ing the name, ID and xpath, just as we do us­ing Firepath in Se­le­nium.

Please refer the com­plete work­ing code men­tioned below:

pack­age com.winium.demo;

im­port java.net.Mal­formedURLEx­cep­tion; im­port java.net.URL;

im­port org.openqa.se­le­nium.By;

im­port org.openqa.se­le­nium.winium.Desk­topOp­tions; im­port org.openqa.se­le­nium.winium.Wini­umDriver;

pub­lic class MyFirstTestCase {

pub­lic static void main(String[] args) throws Mal­formedURLEx­cep­tion, In­ter­rupt­edEx­cep­tion {

Desk­topOp­tions op­tion = new Desk­topOp­tions();

op­tion.setAp­pli­ca­tionPath(“C:\\Win­dows\\Sys­tem32\\ calc.exe”);

Wini­umDriver driver = new Wini­umDriver(new URL(“http://lo­cal­host:9999”), op­tion); Thread.sleep(5000); driver.find­Ele­ment(By.name(“Seven”)).click(); driver.find­Ele­ment(By.name(“Plus”)).click(); driver.find­Ele­ment(By.name(“Eight”)).click(); driver.find­Ele­ment(By.name(“Equals”)).click(); Thread.sleep(5000);

String out­put = diver.find­Ele­ment(By. id(“Cal­cu­la­torRe­sults”)).getAt­tribute(“Name”); Sys­tem.out.println(“Re­sult af­ter ad­di­tion is: “+out­put);

When to use Winium

Use Winium once you are fa­mil­iar with Se­le­nium and are in search of a tool to au­to­mate the Win­dows desk­top ap­pli­ca­tion. Winium fits the bill as you are al­ready aware of most of the func­tion­al­ity in Se­le­nium. There are a few bugs in Winium right now and it is still un­der­go­ing a ma­tur­ing process, just like Se­le­nium once did.

Ref­er­ence

[1] https://github.com/2gis/Winium

By: N.R. Ath­meeya

The au­thor works as a Se­le­nium au­to­ma­tion de­vel­oper at Dell EMC (EMC2). He has six years of ex­pe­ri­ence in au­to­ma­tion test­ing.

Fig­ure 1: Firepath and Fire­bug be­ing used to iden­tify the UI el­e­ment lo­ca­tor for se­le­nium

Fig­ure 2: UISpy show­ing the prop­er­ties of the but­ton ‘seven’ of the cal­cu­la­tor used to find the el­e­ment prop­er­ties for Winium

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.