Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Saturday, January 16, 2010

The Concept of Keyword Driven Framework

In Key Work Driven Framework the script values will be written in Excel files and QTP will execute them using Driver Script. Now this will explain how to execute the script which is specified in Excel Files.

There are majorly two approaches followed to make Keyword Driven Framework.
  1. Specify Script Values Directly in the Excel 
  2. Write Global Functions for each and every application control and specify those functions as keywords in Excel
Approach 1:

In the below table there are 4 columns

Object Class         :- Class of the object on which we are going to perform the operation
Object Properties  :- Properties of the object
Operation            :- The method to perform on the object
Value                  :- Input Data 

image
Please remember that there is no method is available called “SetParent” in QTP. But I am using this word as a condition to set the parent of the object. I have delimited the Parent Object using “/” and respectively I have used it for properties.
To go forward I should have the properties specified in my Object Description Constants.

'Object Properties constants
Public Const GoogleBrowser         = "name:=Google"
Public Const GooglePage             = "title:=Google"
Public Const SearchEdit              = "name:=q"
Public Const SearchButton          = "name:=Google Search"
Why do we need to specify object properties as constants?

We can specify properties directly in place of constants. But when you get a failure in the script, you might not able to identify where exactly the error occurs.

image 

For example, in the above table if the WebEdit step is failed then how do we figure out the failure for which object in the application by just using “name:=q” property. If we have assigned those properties to a constant which is having an understandable name then it will be very easy to identify for which object the failure occurs.
So now we have Excel Keywords and Object Description Constants. We have to write driver script. Follow the below steps prior to write the driver script.
  1. Create a Folder “KeyWordDrivenSample” in “C:\” drive 
    • In this folder create 3 subfolders with the names “Scripts”, “Constants”,”KeyWords
  2. Prepare an excel like how it is available in above table Save the Excel file in the “C:\KeyWordDrivenSample\KeyWords” folder with the name “ScriptKeywords.xls” 
  3. Copy above Object Description Constants in a VBS File and save it in the “C:\KeyWordDrivenSample\Coanstants” with the name “OR Constants.vbs” 
  4. Open a new test in QTP and Save the test in “C:\KeyWordDrivenSample\Scripts” Folder with the name “Driver Script”
Now you should have the Folder structure like specified below

FolderStructure











Now you can save the below script in Driver Script and Run it.
'###################################################################
' Objective            :     This is a driver script for Sample Keyword Driven Framework
' Test Case            :     Driver Script
' Author               :     Sudhakar Kakunuri
' Date Created         :     01/16/2010
' Date Updated         :     01/16/2010
'Updated by            :    Sudhakar Kakunuri
'###################################################################
'##############Initialize Variables and Load Libraries#############################
ExecuteFile "..\..\Costants\OR Constants.vbs"
'#####################Driver Script ######################################
'Add a new sheet and import keywords
Set dtKeyWords=DataTable.AddSheet("Keywords")
Datatable.ImportSheet "..\..\Keywords\ScriptKeywords.xls","Sheet1","Keywords"
'Get Row Count and Column Colunt of the databable
dtRowCount=dtKeyWords.GetRowCount
dtColumnCount=dtKeyWords.GetParameterCount
'Use for lop to get values row by row
For dtRow=1 to dtRowCount
   dtKeyWords.SetCurrentRow (dtRow)
   strObjClass = DataTable("ObjectClass","Keywords")
   strObjProperties = DataTable("ObjectProperties","Keywords")
   strOperation = DataTable("Operation","Keywords")
   strValue = DataTable("Value","Keywords")
   If strOperation="SetParent" Then
       oParentObjectArray=Split(strObjClass,"/")
       oParentObjectPropArray=Split(strObjProperties,"/")
       For iParentCount=0 to ubound(oParentObjectArray)
           iParent=oParentObjectArray(iParentCount)
           iParentProps=oParentObjectPropArray(iParentCount)
               If  iParentCount=ubound(oParentObjectArray) Then
                   strParent=strParent&iParent&"("&""""&eval(iParentProps)&""""&")"
                   Exit For
               End If
           strParent=strParent&iParent&"("&""""&eval(iParentProps)&""""&")."
       Next
       ParentObject=strParent
   Else        
       oStatement=ParentObject&"."&strObjClass&"("&""""& eval(strObjProperties) &""""& ")."& strOperation
       If strValue<>"" Then
       iStrInputDataArray=split(strValue,",")
           For iInputValuesCount=0 to UBound(iStrInputDataArray)
               If  iInputValuesCount=UBound(iStrInputDataArray) Then
                   oStatement=oStatement&" "&""""& iStrInputDataArray(iInputValuesCount) &""""
                   Exit for
               End If
           oStatement=oStatement&" "&""""& iStrInputDataArray(iInputValuesCount) &""""&","
           Next
       End If
       Execute (oStatement)
   End If
Next
'###################################################################
Note: I have given this as a sample. As of now it only works with Test Objects.
_______________________________________
Please send your Suggestions and Doubts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar

30 comments :

  1. The above code is functioning nothing.. just running running successfully...

    ReplyDelete
  2. Hi Dharmender,
    This is just a sample to explain how keyword driven framework is. It's not developed to use directly in any of the project.

    ReplyDelete
  3. hi this is siraj

    it is really good example for keyword driven framework and i worked on it but i did'nt understand if browser name is change(ex:1st browser is google 2nd browser is googlesearch) how can i proceed. so plz reply me i have to get idea on this framework.

    ReplyDelete
  4. Its really good i get some idea and if there is any flow diagram or PowerPoint presentation of the keyword driven its really helpful. Please help me in this regard.

    ReplyDelete
  5. From Long time I am about to implement Keyword driven framework ...Now By Jesus grace and with thehelp of you ...I completed it.

    ReplyDelete
  6. It is really helpful to me

    ReplyDelete
  7. This is wonderful article for beginner. How about the Approach 2 "Write Global Functions for each and every application control and specify those functions as keywords in Excel"?

    ReplyDelete
  8. This is wonderful article. Can you please give us sample script for approach 2 that you mentioned above.
    Thanks in advance!

    ReplyDelete
  9. Excellent article,
    One can manipulate the script to use for his own project.

    ReplyDelete
  10. Good Explanation.It helped me alot.Thank you.

    ReplyDelete
  11. thanks for helping our seo people with ur info

    ReplyDelete
  12. Hi All,

    I need to undrstand Keyword Driven Framework, Though i understand it theoritically i need to work practically & check..

    I know i need to have QTP installed,Create the folder structure mentioned above & copy the script, run it..How do i come to a conclusion that the framework worked?

    ReplyDelete
  13. Good Explanation.It helped me alot.Thank you.

    ReplyDelete
  14. Hi,this is a nice article.
    I hope we can modify the parameers accordingly and use i in live project..rite?

    ReplyDelete
  15. Hi this is nice artile.
    One doubt I have of using OR constants.vbs, suppose we have 1000 object then we need to create 1000 constant variable which is not a good approch.

    ReplyDelete
  16. can you please write driver script for data driven framework

    ReplyDelete
  17. I need driver script for data driven framework

    ReplyDelete
  18. thnx sir nice example

    ReplyDelete
  19. good article sudhakar..

    its simple and sweet..

    thanks

    ReplyDelete
  20. good one
    one doubt what will be the value of parentobject in the Else part

    ReplyDelete