Reading Time: < 20 minutes
What’s up Guys! Welcome to automationcalling.com
I believe this topic is pretty much exciting and interesting topic for you guys. In fact, there is a lot of buzz and expectation of how to automate windows application in open source option. Well, I’m sure there is no surprise if I recommend tools like UFT, Test Complete, Coded UI etc., for automating Windows Application but those are licensed tool.
Before explain about brief introduction on Windows Application Automation, there are some questions in my mind, perhaps the same questions from your side too!. In fact, I take this opportunity to write some questions from my side or behalf of you regarding current challenges :-).
- My company recommends to search open source tools, can I have tool which supports automation for windows application?
- My existing framework had been implemented in Java, I don’t want to go for different tool for windows application automation as my framework supports Web browser as well as Mobile
- I’m using Selenium in Visual Studio for automating web browser but my company is asking me to research a tool which support automation for windows application that should be implemented in Visual Studio.
- This is more or less point no.2 question. How to integrate one framework, one solution.
The answer in case for Open source is Big Fat Yes, I personally prefer and may recommend below listed tools which are:
- Microsoft WinAppDriver
- Winium
- AutoIT
- Sikuli
- Pywinauto
- RobotClass
Each tools and supported languages have unique PROS and CONS. I’m not going to say in this blog about which tool is better (may be in my future blogs) rather I would say if you are fan of Selenium then I would say you are in the right place reading right blogs ;).
Yes, Today I’m going to explain little about Microsoft WindowsAppDriver, Framework implementation strategy as well as sample application for Calculator and MS-Paint automation.
Features of this Framework:
- Implemented using PageFactory Design patter + RobotClass Util
- This is just base framework where you can implement or customize all wrapper methods of WindowsAppDriver as well as RobotClass in future based on your requirements and needs.
- Easy to integrate with Selenium/Java Project
- Locator like accessibility id may not support PageFactory, hence recommend to use direct implementation like “WebElement element=driver.findElementByAccessibilityId(“XXX”)”
- Just instantiate page factory constructor which is fair enough.
Getting Started
Introduction
Microsoft Windows Application Driver (shortly called WinAppDriver) is a service to support Windows Application tool similar like Selenium. It supports windows app like Win32, VB6, WPF, UWP. The WinAppDriver enables Appium by using its API call that were added in Windows 10 to test any windows based application.
Note: WinAppDriver supports Java, C#, Ruby and Python
Installation/Prerequisites
- Should have any Windows 10 PC (could be Home or like Enterprise/standard etc.,)
- Java 8 and above
- You should have Admin rights in your PC
- Enable developer Mode by typing “Use developer feature” in search at bottom left
- Download and install Windows-10-SDK https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
- Download and Install latest Windows Application Driver can be found: https://github.com/Microsoft/WinAppDriver/releases/
- After download, Navigate to the location C:\Program Files (x86)\Windows Application Driver and run “WinAppDriver.exe”. This is your prerequisites before run WinAppDriver code. Hence, write automated code to call batch script or use pre-configuration in your jenkins job.
POM Dependencies:
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.12.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.14.3</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/io.appium/java-client --> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>6.0.0</version> </dependency>
Locator Strategy:
Client API | Locator Strategy | Matched Attribute in inspect.exe | Example |
---|---|---|---|
FindElementByAccessibilityId | accessibility id | AutomationId | AppNameTitle |
FindElementByClassName | class name | ClassName | TextBlock |
FindElementById | id | RuntimeId (decimal) | 42.333896.3.1 |
FindElementByName | name | Name | Calculator |
FindElementByTagName | tag name | LocalizedControlType (upper camel case) | Text |
FindElementByXPath | xpath | Any | //Button[0] |
Inspecting Elements:
There are some tools which actually helps and support inspecting objects properties in windows application. Let’s go “Inspect.exe” as WinAppDriver GitHub recommends Microsoft Native tool.
- Navigate to Windows SDK folder which present under C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64
- Open Inspect.exe
- one of the example, opened a calculator and inspect the element, please refer the below snapshot
UI Recorder:
UI Recorder is a native App offered in WinAppDriver GitHub which actually helps to inspect as well as generate C# code for your recordings. This will help us to perform some unrealistic issues which can be analyzed using this tool
UI Recorder:
- https://github.com/Microsoft/WinAppDriver/tree/master/Tools/UIRecorder
- https://github.com/Microsoft/WinAppDriver/wiki/WinAppDriver-UI-Recorder
Note: I opened a bug (https://github.com/Microsoft/WinAppDriver/issues/437) in GitHub regarding UI recorder doesn’t launch in windows. Hopefully it will be be available in next release.
Test Automation Strategy:
PageFactory Desgin Pattern + Implemented Robot Class which actually help some unrealistic automation condition like difficult to recognize object etc.,
WinAppDriver Wrapper | Incorporated both Selenium Methods and WinAppDriver methods |
Page Factor Design patter | This class holds page objects and extends WinAppDriver class |
Robot Class Wrapper | Incorporated both Mouse and Keyboards base Methods. In case unrealistic issue we can handle using Robotclass methods. |
WindowsDriver Constructor Instantiation:
try { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setCapability("app", new CommonUtil().getPropertyFileValue(applicationPathOrAppName)); driver = new WindowsDriver(new URL(new CommonUtil().getPropertyFileValue(winAPPDriverServer)), desiredCapabilities); driver.manage().timeouts().implicitlyWait(WAITTIME, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); }
Note:
For Windows Native App -> Go to Task Manager -> Right click on Calculator application and select properties. Take a look on Name which looks like this “Microsoft.WindowsCalculator_10.1705.1301.1000_x64__8wekyb3d8bbwe” this must be changed to “Microsoft.WindowsCalculator_8wekyb3d8bbwe!App” (I removed version and 64 bit as well as added “!App” end of the text)
For exe, for eg Installer or launch exe application: parameter needs to pass like this “
D:\\Windows\\System32\\mspaint.exe for above constructor in setCapbility Pass Server details like "http://127.0.0.1:4723/" in new WindowsDriver()
The above server is default when you launch Windows Application Server.
Calculator and MS-Paint Automation Examples:
@Test, @calculatorExamples public void additionCalculation() { calculatorPage.clickOn(calculatorPage.getButton9()); calculatorPage.clickOn(calculatorPage.getMultiplyButton()); calculatorPage.clickOn(calculatorPage.getButton7()); calculatorPage.clickOn(calculatorPage.getEqualButton()); Assert.assertEquals(Integer.parseInt(calculatorPage.getCalculationResults()) , 63); }
@Test, @MsPaintExamples public void moseMove() { try { msPaintPage.buttonclick(msPaintPage.getOvalShape()); msPaintPage.mouseDrawPicture(137, 130, 137, 500); msPaintPage.clickOn(msPaintPage.getmspaintCloseButton()); msPaintPage.clickOn(msPaintPage.getDontSaveButton()); } catch (Exception e) { e.printStackTrace(); tearDown(); } }
To clone/download this framework, please feel free to visit: https://github.com/automationcalling/WindowsAutomation_WinAPPDriver
Limitations & Issues:
Recommend to see list of open issues in GitHub: https://github.com/Microsoft/WinAppDriver/issues
- WinAppDriver GitHub updates done regularly, so need to wait for some open issues.
- At this moment support only Windows 10, not sure about other versions.
- Other languages examples are less compare to C#
- The WinAppDriver code is not currently open-source. Samples, tests, and related tools are open-source. We’re investigating the possibility of open-sourcing the WinAppDriver code.
Conclusion:
WinAppDriver is a nice and alternate option for existing license tool in the market which helps to implement and integrate one platform and one solution for your automation projects. This tool will also help to perform Windows Automation, if my prediction is correct this will grow and may help for RPA automation too. In case of any unexpected conditions, unrealistic issues, it’s possible to integrate RobotClass or Sikuli in part of Java project to overcome challenges.
Article is awesome. My suggestion is post short video on this it will be helpful to understand easily.
LikeLiked by 1 person
Point Taken. Sure, will do it in future blogs.
LikeLike
Hello, Thank you for the blog, it did help me to create Page objects for my WinAPPdriver Project, But i am facing a null pointer exception in Login Step def. Could you please help?
LikeLike