Friday, 28 October 2016

Robot Framework and Windows GUI Automation with AutoItLibrary

Web test scenarios sometimes involve native Windows components that Selenium cannot access. I show how to use AutoItLibrary to automate Windows components inside a web test scenario written in Robot Framework and Selenium Library.

Usage of Robot’s external test libraries should be considered at first place. Alternatively AutoIT or other tools can be independently used to automate their parts and call these scripts from Robot code. That is one option when the library does not support the needed functionality. However it is an advantage to have all the control under single framework.

Certain dialogs, file browsing or sending email are examples of Windows components that may appear as part of the web test scenario. My example test case performs an XML validation for a file at http://www.xmlvalidation.com/. To pick up a file to be uploaded, an operating system/browser specific file browser component is launched. In Windows environment, AutoIt functionality is needed to take control over that window and type in the file name and click Open button. After that Selenium Library keywords are used to continue the web test flow.

AutoITLibrary and installation instructions can be found hereIt is a wrapper like keyword library to AutoIt, a free tool for automating the Windows GUI. Keyword documentation can be found locally from C:\RobotFramework\Extensions\AutoItLibrary\AutoItLibrary.html and in practise the function specs at AutoIt pages are an essential reference for the usage, for example to use keyword Control Click, see https://www.autoitscript.com/autoit3/docs/functions/ControlClick.htm

AutoIt comes with an inspection tool, Au3Info.exe (installed under C:\RobotFramework\Extensions\AutoItLibrary), that can be used to get the information needed to locate the Windows UI elements such as text fields and buttons. Drag the Finder Tool over the area to be inspected. The tool is used here to see that classname ”Button1” is a proper identifier for the Open button.



Similarly it can be inspected that "Edit1" is an identifier for the text field where file name is inputted. In the Robot code we first wait that the window named "Open" is detected, then input the file name and click Open and continue by clicking the validation button at the web page. Finally the success message is expected.


In this example the UI elements can be inspected and uniquely identified. X and Y offset values can be used to click certain position of the identified area. Proper UI mapping should be made instead of hard coding. In case no elements cannot be inspected, tools based on image recognition like Sikuli are an option to consider. I demonstrate that one at the next post. By the way, in the video there are a few sleep commands added for demonstration purposes.
video

2 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Robot framework, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Robot framework. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com



    ReplyDelete