QTP Parameterization (all types)
The what?
Parameterization is a process in which you can pass multiple sets of data, variables to remove hard coded values. For example, if you need to check ten login credentials if they are valid or not, worst approach to be adapted by you will be executing the code ten times, problem redundancy and wrong approach. Alternatively you can just pass values in the datatable (Excel like sheet provided in QTP). so you can test multiple set of data in one action or call.
The ways?
There are three ways to parameterize your data using QTP.
Parameterization is a process in which you can pass multiple sets of data, variables to remove hard coded values. For example, if you need to check ten login credentials if they are valid or not, worst approach to be adapted by you will be executing the code ten times, problem redundancy and wrong approach. Alternatively you can just pass values in the datatable (Excel like sheet provided in QTP). so you can test multiple set of data in one action or call.
The ways?
There are three ways to parameterize your data using QTP.
- Using Datatable (Global or Action specific)
- Using environmental variables (User defined, Built-in)
- Using Random (built-in function)
1. Using DataTable
Datatable values can be used in two ways. Either using Global sheet or Action specific sheet. Global sheet as the name says allows acess throughout your test, across functions or actions, the data (columns) declared here can be used globally within the test. Syntax is given below.
Datatable values can be used in two ways. Either using Global sheet or Action specific sheet. Global sheet as the name says allows acess throughout your test, across functions or actions, the data (columns) declared here can be used globally within the test. Syntax is given below.
''''''Decalare and Set
Set DataTable("Username",dtGlobalSheet)
‘dtGlobalSheet’ instructs QTP to create a column Username in the Global sheet. If we replace dtGlobalSheet by dtLocalSheet, that will instruct QTP to create the column in the current action sheet you working in like Action1(Default). After filling test data into the datatable, browse Action1 and Select Action Call properties. Run tab shows various options, select option 2 and the test will execute on all datatable values.[Refer Screenshot below]
Datatable parameterization |
2. Using Environment variables
These variables are considered as global variables, if you have declared them once you can use them within or across actions. Same as you use parameters of a global sheet. Difference is these are variables.
These variables are considered as global variables, if you have declared them once you can use them within or across actions. Same as you use parameters of a global sheet. Difference is these are variables.
For example you have a page which requires your digital signature i.e. First name, last name and Date of birth to be input. So to avoid copy pasting the same line of code again and again what you can do is declare and use user-defined environment variables.
''''''declaration
Environment.Value("firstname") = "define value"
''''''Calling
Browser().Page().WebEdit().Set Environment.value("firstname")
There are build-in environment variables as well. To access them Click on File > Test Settings and Click on Environment tab. List of build-in variable will be displayed, which can be used in the same way, we call in the user define environment variables. If your test is not executing make sure you have not used incorrect spelling.
Buil-in Environment variables |
3. Random Numbers
You can always use a random number function with multiple scenarios. For example if you have to download and save an image from all pages and the image has the same name every time the test runs, you will face errors. So to get rid of this problem use random number where you are saving the file.
You can always use a random number function with multiple scenarios. For example if you have to download and save an image from all pages and the image has the same name every time the test runs, you will face errors. So to get rid of this problem use random number where you are saving the file.
''''''SyntaxRandom(num1, num2)
Here num1 is the start range and num2 is the end range. The Maximum allowable value is 2147483647. To save file add the random function with an ampersant (&).
Dialog("text:=Save As").WinEdit("attached text:=File &name.*").Set "Downloaded image" & RandomNumber(1,99) & ".jpeg"
Heres all from my side on various ways of parameterizing your QTP test data. Learn and practice, you will get to discover other good and easy ways.
Comments
Post a Comment