Sunday, 21 September 2014

QTP - Keyword driven Framework

How can we make the above linear framework test better? How can we overcome the cons?

Obviously, we need reusability, modularity and readability. Trying to incorporate these features and arriving at an optimum solution is nothing but an attempt at creating a new, more improved framework.
What are the reusable components?
  1. Launching of gmail and arriving at the ‘Google Accounts’ page. This is a given, since validating this page means to first get here. ‘GoTo Google Account” – can be made into a separate function that can be called over and over again.
  2. Enter the details and validating them – You can further break this up into positive and negative blocks to include more level of modularity
  3. Account creation – The final level of validation and accomplishing the task at hand
Once you have arrived here, not only have you identified components that can be called over and over again, but you have also broken you linear program into modules.
Functions:
So far in our series we have not dealt with functions. Functions are nothing but a piece of code that does a certain operations. It accepts input parameters from the program that calls it and returns value to it.
As a general practice all the reusable pieces of code are grouped into a file that contains all the reusable functions. This file is associated as a resource to your QTP test.  Typically a function library can be a file of the type: .vbs, .txt or .qfl
Back to our example – This is how the function library file can be:
Function gotoGoogleAccount()
'Open Gmail
SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
'Page Sync
Browser("Gmail").Page("Gmail").Sync
‘Click on create account
Browser("Gmail").Page("Gmail").WebLink(“Create Account”).Click
‘Enter the details
End Function
Function EnterDetails()
Browser("Gmail").Page("Google Accounts").WebEdit(“First Name”).Set “Swati”
Browser("Gmail").Page("Google Accounts").WebEdit(“Last Name”).Set “test”
‘Fill in several other details
End Function
Function SubmitToCreate()
‘Submit
Browser("Gmail").Page("Google Accounts").WebButton(“Next Step”).click
End Function

Now your actual script will be:
'Open GMail
gotoGoogleAccount()
‘Enter the details
EnterDetails()
‘Submit

SubmitToCreate()
From the above program it is now clear that we have achieved readability, modularity and if in case another program wants to use the login function, we can surely reuse it. All you have to do is associate the function library to that new test too and you are good to go.
You can also see that in your script the function names are functioning as if they are VBScript’s keywords and hence the name for this framework.
The components or test assets in this kind of frameworks are:
  1. Test scripts
  2. Shared OR
  3. Shared function library
Now, what else would make this program even better? If we could make the EnterDetails() function to take different sets of data and create different accounts and not be limited to the data that we hard coded into the program. That exactly is the next step. Data driving your tests and the approach where we do this is the data driven framework.

No comments:

Post a Comment