Demystifying Keyword Driven Using Watir

2,178 views

Published on

Published in: Technology, Design
1 Comment
2 Likes
Statistics
Notes
  • Good one! Explained in simple terms, and very beautifully.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,178
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Demystifying Keyword Driven Using Watir

  1. 1. Demystifying Keyword Driven Using WATIR Inspiration: 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 Baby Steps: 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. Roadblock: 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 Framework. 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.
  2. 2. Step 1: 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. Object 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 Vlaue • 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 Step 2: 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 Step 3: 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 Keyword Explaination 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 :
  3. 3. 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 End Case End For End Loop Close Excel File Step 5: Created Excel File as follows Actu Objec al t Prop Expecte Out Keyword Name Object Prop Value d Output put Parm_01 Screenshot_Name OpenURL http://www.google.co.in/ SetText name q Astadia ClickButto n value Google Search ClickLink href http://www.astadia.com/ Result Astadia To get an object property and value, use Firebug (Add on for Firefox) or IE Developer Tool bar. Step 6:
  4. 4. Write code in WATIR and save the file with extension rb #Include The Library require 'win32ole' require 'watir' require 'watir/IE' require 'D:AKFWorkingCodeUtility.rb' require 'watir/screen_capture' include Watir include Watir::ScreenCapture begin #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 case Keyword when /^OpenURL/ @Browser=IE.start(Parm_01) @Browser.maximize when /^SetText/ @Browser.text_field(:quot;#{Object_Prop_Name}quot;, Object_Prop_Value).set(Parm_01) when/^ClickButton/ @Browser.button(:quot;#{Object_Prop_Name}quot;, Object_Prop_Value).click when/^ClickLink/ @Browser.link(:quot;#{Object_Prop_Name}quot;, Object_Prop_Value).click when/^CloseURL/ @Browser.close
  5. 5. when/^Result/ Actual_Output=verify_text(Expected_Output,quot;Passquot;,quot;Failquot;) worksheet.Cells(j, 5)['Value']=Actual_Output time_stamp_s = Time.new.strftime('%m%d_%H%M_%S') screenshot_filename=quot;#{time_stamp_s}_#{Expected_Output}quot;+quot;.jpgquot; screen_capture(screenshot_filename,active_window_only=false, save_as_bmp=false) worksheet.Cells(j, 7)['Value']=screenshot_filename workbook.SaveAs('D:AKFWorkingCodePOC.xls') else quot;Exitquot; end end end workbook.Close() excel.quit() rescue workbook.Close() excel.quit() end Step 7: Following will be output of excel after executing above script. Objec Actua t Expecte l Prop d Outpu Keyword Name Object Prop Value Output t Parm_01 Screenshot_Name http://www.google.co. OpenURL in/ SetText name q Astadia ClickButto n value Google Search http://www.astadia.co ClickLink href m/ 0521_1613_55_Astadia.j Result Astadia Pass pg Author Biography:
  6. 6. 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 hlamba@astadia.com

×