We are working our way through figuring out how to derive an Automation Framework that works best for a certain testing project and also defining certain frameworks that already exist.
The example that we were using in the previous QTP framework article was creating a new Gmail account.
To start with, we coded the creating a new account scenario just by record and playback in a linear fashion. Seeing how much it lacked in modularity, readability, and reusability, we broke it down into functions that would be referenced as keywords moving forward.
=> Click Here For The QTP Training Tutorials Series
We did achieve modularity, readability, and reusability through this method but we needed to make the program even more robust so that it can take different sets of values without having to modify the script itself.
That is exactly what we are going to achieve by data driving the tests.
Table of Contents:
Data-Driven Automation Framework Using QTP
Creating multiple Google user accounts is a task that we will try to accomplish using this framework.
In the earlier example, we hardcoded the first name, last name, user id details, etc. into our code while trying to create an account. We will have to separate the code from the data if we have to achieve the data driving aspect for this script.
The data should come from a source that is not the program itself.
Typically the Data input can be anything:
- MS Excel files
- Database
- Text files
- XML files….etc.
Excel files are the ones that get used most often. The very fact that each action in QTP comes integrated with a datasheet of its own explains why that’s so.
You can use one or more data sources for a single script. The excel sheet that comes with the action can be used or you can use an external excel sheet too. Basically, a data sheet can be any relevant external file.
For Example,
Here is the code that we need to data drive:
Browser("Gmail: Email from Google").Page("GoogleAccounts").WebEdit("FirstName").Set "swati" Browser("Gmail: Email from Google").Page("Google Accounts").WebEdit("LastName").Set "s" Browser("Gmail: Email from Google").Page("Google Accounts").WebEdit("GmailAddress").Set "test"
All the data right now is hardcoded. Let us now see how we can take these values from the datasheet.
Go to the expert view for the statement in QTP and click on the value column for a step.
The following window opens up:
Select the parameter option, choose a name for the parameter (this will be the column name in the datasheet), and choose whether you are going to use the global sheet or local sheet (global sheet is available for all the actions in a test, but the local sheet is specific to the current action).
For the “Name” field on the screen, QTP provides a default value. The user has the option to keep it the same or change it.
Upon clicking OK, a new column gets created in the data table.
This is how the datasheet that contains 3 sets of the first name, last name, and account id looks like:
Once parameterized, the code looks as shown below:
Browser("Gmail: Email from Google").Page("Google Accounts").WebEdit("FirstName").Set DataTable("G_First_Name", dtGlobalSheet) Browser("Gmail: Email from Google").Page("Google Accounts").WebEdit("LastName").Set DataTable("G_Last_Name", dtGlobalSheet) Browser("Gmail: Email from Google").Page("Google Accounts").WebEdit("GmailAddress").Set DataTable("gmail_address", dtGlobalSheet)
If we have to create these 3 user IDs with the data in the sheet, we need to have 3 iterations. Iteration is nothing but a test run.
Once the data is set up, we will have to instruct QTP on how many times this code needs to run, or how many iterations.
Here’s how we do it: Go to File -> Settings and Run
In the above screen, set the iteration properties as required.
Alternately, you can instruct QTP about the iterations programmatically. As always, this allows more control as well as programming skills. So it is really up to the comfort level of the tester to choose either of these methods.
The components of the data-driven framework are:
- Test script
- Data files
- Shared Functional library (if it exists or could be a linear program).
- Object repository (Again, this component will not exist if descriptive programming was used to create objects).
The test results will show a “Passed’ or ‘Failed’ status for each test run.
Apart from the data table that comes by default, we can use any external excel file as an input sheet.
Hybrid Framework
In the above example, you used keywords (names of the functions that the user has created) and have data-driven the test to make sure that different users are created at the same time. This is nothing but a hybrid framework.
The combination of any two or more frameworks that we have discussed so far is a hybrid framework. In my experience, no framework works effectively for a certain project. The hybrid framework is what gets used most often.
Few important points about frameworks:
- The framework is just a solution that worked best in a certain situation but should not be construed as a set of rules to be definitely followed. It should be seen more like guidelines.
- There might be many other frameworks in use, we have only listed and explained the common ones.
- Nomenclature – Different people address their frameworks with different names. So if the names are slightly different from one application to another, then it is normal.
- Most frameworks can be used in conjunction with one another when any one of them cannot provide an all-around solution to your testing goals.
Conclusion
For the sake of easy understanding, we have really simplified the concepts of the framework here.
If you have any framework-related issues that you are facing, but are not covered in these articles, then do let us know. We will most definitely try to answer your questions. Feel free to post your questions.
=> Visit Here For The QTP Training Tutorials Series
Hello,
Can you let me know if multiple iterations of a particular piece of script is possible with keyword driven framework or not? Like for example, providing mulitple inputs to the flight details in the sample application provided by qtp? how will we achieve this through the keywords?
Regards,
Pankaj
good one. but i am interested in selenium. please, start same series for selenium users.
@Swati @Vijay
I have a similar question but I do not find the code for it, how to implement fetching of data from the external source(not the data table in QTP) and to use each set of data in that external data source(for e.g., Spreadsheet) in a loop for iteration…Can you put a explanation of the process and also the code to implement it
very nice explanation
Excellent, very nice explaination
What is the difference between Keyword driven and Modular framework?
From the above discussion it seems modular is explained as Keyword driven. I am confused, please help!!
this is not fream work post.
This is peramterizaing
1. Please post difficult automation framework interview questions.
2. Some real time examples of three tier application and the kind of framework to be used with folder structure also.
Thanks..
Good Explanation. So far i had done what this article showing. But idk what i had done with my code is on of framework concept 😀 Thanks for sharing
Can anyone tell me that how to connect to oracle database through QTP.
@ Chetan – we’ve published two tutorials on same day so ou should have received a single email with links to two tutorial.
Here is the 17th Tutorial –
https://www.softwaretestinghelp.com/qtp-tutorial-17-test-automation-frameworks/
plz send me all the tutorials in my mail.i realy need it
Hi Swati
I have one question, in QTP after executing the script will it be the final script because again in QC we execute the same script from Test Lab. Why we should execute 2 times from QTP and QC. And from QTP directly we can add the defect after executing the script?
Thanks
Hi sir I need a answer for did you checkpoints, recovery scenario, environment variable in ur project
With example. Can you tell me how to explain .
I know all the concept but I don’t how to explain like related with my project
Is tutorial 17 missing? I got 18 after 16 via email???
@sumeet: tutorial 17 is not missing. please recheck, its right before tutorial 18.
Its really simple and easy to understand.
How it work the Hybrid Framework. Please explain in deep and mail me.
Email: kumar.prakash@hotmail.com
Thanks & Regards,
Prakash
@Remya: The code is in the above article. Please refer to it and let me know if you need more info.
Good work, Vijay and Swati… This is a comprehensive series of QTP tutorials which is really helpful for newbies…
Cheers!
Very nicely explained.
Swati,
can you please explain how External Excel files can be used for Data Driven framework.
How can we use excel sheet as input sheet. Please explain. A piece of code will also do. Thank you.