Tuesday, 23 September 2014

Parameterization in QTP

What is QTP parameterization?
Sometime application does not accept the duplicate data records. In this case if you run same test script with fixed set of input data, application may throw an error due to data duplication. To avoid this issue, QTP provide ways to accept different test inputs to the test script. This process of providing different input values through external parameters is called as parameterization

Types of parameterization in QTP
The variable value can be or the parameter types can be:

  1. Data Table parameters
  2. Test/Action parameters
  3. Environment variable parameters
  4. Random number parameters

Parameterization in QTP using Datatable with Example

Parameterization in QTP using Excel
I checked the parameter value ON and then the there is a location in Datatable field following the name.

Name: The corresponding column name in the data table from where the data needs to be taken. By default QTP will suggest a name. You have an option to keep it as suggested or change it as needed.
Global Sheet:  This sheet of data is available to all the actions in a test.
Current action sheet or local sheet:  as the name suggests, it is the sheet of data that is available to a certain action.
I am going to multiple rows of data to the Global data sheet. This is where the password encoder tool comes in handy. You can put in encrypted values in your data sheet that you get from this tool.







Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Email").Set DataTable("SignInName", dtGlobalSheet)
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Passwd").SetSecure DataTable("GPassword", dtGlobalSheet)
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebButton("Sign in").Click
Browser("Gmail: Email from Google").Page("Gmail - Inbox").Link("Sign out").Click

You will see in the above code that the values for the email ID and password are taken from datatable.
This code will run for all the 4 rows of data in the global sheet if in the following screen I set the option “Run on all rows” ON:

QTP Parameterization using Environment Variables

 

Environment variable is a value that remains the same throughout a test run unless explicitly changed by the program.
3 types of environment variables:
  1. User defined internal
  2. User defined external
  3. Built in
We will start with built in variables because that is the simplest.
Built in variables are created by QTP itself and contain information about the test path, operation system etc. These are read only and hence can only be used by the user as they are.

Example- msgbox Environment ("OSVersion")

User defined – external:  In case when we need to have an entire list of environment variables available for a test, the user has an option to create it externally and associate it to the test and make those variable available to this test.
Typically, this file is an .xml with the structure as follow and is available on your desktop:

<Environment>
<Variable>
<Name>First Name</Name>
<Value>Swati</Value>
</Variable><Variable>
<Name>LastName</Name>
<Value>Seela</Value>
</Variable>
</Environment>
Once this is set, we can add this file to the test by going to File->Settings->Environmentand selecting “User defined” from the drop down:

In the screen, you can see the option to add the file, so ahead and add it.
Alternately, if I need the variables in this test for another one, I can export them into a file by clicking on “Export” option.
So now that we know how to set and use environment variables, there is yet another use for these:
In case, we set the values for URL_env and Browser_env variables, then the record and run settings set overrun and no matter what you set there, it is going to consider the values that these variables contain.


 




No comments:

Post a Comment