Demystifying Keyword Driven Using WATIR
While working for growing organization where QA budget is limited and cannot afford to
spend thousand of dollars on commercial tool like WinRunner/QTP, a need was felt
within QA team to use automated functional tool.
WATIR (Web Application Testing In Ruby) was selected as freeware tool for POC.
WATIR can be downloaded from http://wtr.rubyforge.org/install.html
After downloading WATIR, QA team started reading through the documentation and
quickly realized that it is extremely user friendly and does not take much time to write
first functional automated test.
Soon we started creating automation test cases and as the count of test cases grew, the
maintainability of WATIR code started to become a big problem. A need for framework
was felt and since everyone in QA world talks about Keyword Driven framework, we
decided to implement the same.
QA team Google and found thousands of document related to Keyword Framework on
internet. All of the documents talk about “WHAT” instead of “HOW” to create Keyword
QA Team took this up as challenge and decided to build Keyword Framework with
minimum strings attached.
The following pages talk about “HOW” to implement Keyword Framework. We hope,
this document will help demystify the Keyword Framework and knowledge will be
accessible to everyone instead of fortunate few.
Identify and understand the fields available on Excel sheet
Excel sheet is use to separate the code logic and data. Test data and the
operations/sequence of the test is planned in external data file.
Prop Object Prop Expected Actual
Keyword Name Value Output Output Parm_01 Screenshot_Name
Column Name Explanation
• Keyword : They are special words which would be use to drive the code
• Object Prop Name : Each object on webpage can be identified by Property Name
• Object Prop Value : Each object on page layout can be identified by Property
• Expected Output : This column contain the expected result
• Actual Output : The text step pass or fail
• Parm_01: Parameter use to enter/select data on webpage
• Screenshot_Name : Use to store the screenshot name of Actual result
Following are the high level test steps which would be automated using WATIR
• Open Browser and navigate to Google
• Enter “Astadia” in search text box
• Click on website for Astadia
• Verify text Astadia on website
Identify the Keywords to be use. Keywords chosen should be self explanatory as this will
help to transition the work of creating testcases to manual testers allowing automation
expert to concentrate on writing code.
Following Keywords were identified
OpenURL Use to open IE browser and navigate to specific URL
SetText Use to write text to textbox
ClickButton Use to click on button
ClickLink Use to click on link
Result Use to compare expected and actual result.
Step 4 :
Write Pseudo Code and then we will convert it into WATIR
Open Excel File
Loop through each sheet
For each row in sheet
Use CASE statement and perform actions depending on Keyword
Close Excel File
Created Excel File as follows
t Prop Expecte Out
Keyword Name Object Prop Value d Output put Parm_01 Screenshot_Name
SetText name q Astadia
n value Google Search
ClickLink href http://www.astadia.com/
To get an object property and value, use Firebug (Add on for Firefox) or IE Developer
Write code in WATIR and save the file with extension rb
#Include The Library
#Open Excel File
excel = WIN32OLE::new('excel.Application')
excel.DisplayAlerts = false
workbook = excel.Workbooks.Open('D:AKFWorkingCodePOC.xls')
#Loop through the worksheets
for i in 1 .. workbook.Worksheets.Count
worksheet = workbook.Worksheets(i)
rowcount = worksheet.UsedRange.Rows.Count
for j in 2..rowcount
Keyword =worksheet.Cells(j, 1).value
Object_Prop_Name = worksheet.Cells(j, 2).value
Object_Prop_Value = worksheet.Cells(j, 3).value
Expected_Output = worksheet.Cells(j, 4).value
Parm_01 = worksheet.Cells(j, 6).value
time_stamp_s = Time.new.strftime('%m%d_%H%M_%S')
Following will be output of excel after executing above script.
t Expecte l
Prop d Outpu
Keyword Name Object Prop Value Output t Parm_01 Screenshot_Name
SetText name q Astadia
n value Google Search
ClickLink href m/
Result Astadia Pass pg
Hirday is currently working as Sr. Manager (QA & CS) in Astadia. He has more than 9
years of IT experience. He is responsible for competency development of the Testing
Group in Astadia.
Hirday is M.S.(Computer Science) from Widener University, USA.
He has worked on development and implementation of software test planning and
framework for test automation on .NET platform.
He can be reached at firstname.lastname@example.org