Parameterization in QTP Explained with Examples (Part 1) – QTP Tutorial #19

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated November 27, 2024

What is QTP Parameterization?

Sometimes the application does not accept duplicate data records. In this case, if you run the same Test script with a fixed set of input data, an application may throw an error due to data duplication. To avoid this issue, QTP provides ways to accept different test inputs to the test script.

The process of providing different input values through external parameters is called as Parameterization.

=> Click Here For QTP Training Tutorials Series

Parameterization in QTP

Types of Parameterization in QTP

The variable values can be or the parameter types can be:

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

In this QTP tutorial, we will focus mainly on Parameterization using Datatable. We will explain other types of Parameterization methods in the next tutorial.

Parameterization In QTP

Say you are trying to write a program that checks the login values for a couple of users on gmail.com. The following is the code that you have for one user but you want the same to take different values each time. How do you do this?

Code to sign in to Gmail for one user:

SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set "swatiseela"
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").SetSecure "sfgs686898"
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

Now, go to the Keyword view and click on the value column for the email id and password set statements.

Given below is the typical screen that comes up when you are trying to parameterize:

QTP Parameterization datatable

As you can see, the value can either be a constant, “swatiseela” in this case, the login ID.

Or if you choose the parameterize option then the corresponding fields on the screen get activated.

QTP Parameterization datatable

From this screen, you can choose to parameterize the chosen value with either a value of the data table, environment variable, or a random number. Since the most often used source is the data table, we will discuss that first.

Apart from these, you could use the input and output values of a certain action as a parameter for a value. We will discuss that too in a while.

Parameterization in QTP Using Datatable with Example

Parameterization in QTP using Excel

I checked the parameter value ON and then there is a location in the 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 the option to keep it as suggested or change it as needed.

Global Sheet:  This sheet of data is available for all actions in a test.

Current action sheet or local sheet: As the name suggests, it is the sheet of data that is available for a certain action.

I am going to add multiple rows of data to the Global datasheet. This is where the password encoder tool comes in handy. You can put encrypted values to the datasheet that you get from this tool.

This is what my data sheet looks like:

QTP Parameterization datatable

After parameterization this is how the code looks like:

SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
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
Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
Browser("Gmail: Email from Google").Close

You will see in the above code that the values for the Email ID and password are taken from the data table.

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 datatable

Just in case, if you don’t want to use the above screen to decide how many rows the code needs to be executed for you to be able to do it programmatically. To do that, you need to select the option “Run one iteration only” on the above screen and write the code the following way:

for i=1 to datatable.GetRowCount
SystemUtil.Run "iexplore.exe", "http://www.gmail.com"
Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
datatable.SetCurrentRow(i)
varName=datatable.value("SignInName")
varPwd=datatable.Value("GPassword")
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Email").Set varName
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Passwd").SetSecure varPwd
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
Browser("Gmail: Email from Google").page("Gmail: Email from Google").Sync
Browser("Gmail: Email from Google").Close
next

Upon executing a test that runs for 2 iterations, this is how the test results screen will look like:

QTP Parameterization datatable

I would like to spend some time examining the code and trying to understand why each line and its order is important for the successful execution of the test:

  • Why am I opening the browser within the ‘for’ loop?
  • Why are there sync statements everywhere?
  • Why are we programmatically closing the browser at the end instead of letting the “Record and run settings – Close the browser when test closes” option take care of that for us.
  • Again, why is the close statement inside the ‘for’ loop?

Please note that in the above piece of code, I did not declare the variables in this test, indent the statements or provide comments. This is deliberate as I did not want to dilute the essence of the statements.

The following concept will answer these questions:

State of your AUT:

The basic rule is – Each iteration should begin with the AUT being in the same state and ending in the same state.

  • If the statement to open the gmail.com page was outside the for loop, then the test would run fine for the first iteration but for the next one the gmail.com page would not have been opened and the test would fail.
  • If the statement to close the browser is not included in the test, then the test would open a browser with each iteration and you would end up having as many instances of the browser open to the number of rows in the data table.
  • Imagine if the closing statement was outside the for loop, then also you will end up with too many browsers.
  • Sync statement: This forces the QTP test to wait until a certain page loads up completely before it starts performing a certain operation on it.

Always try to return your application to the state where it began. This will ensure that you provide the same interface for each of your iterations to interact with.

The following is the piece of code when you are using a local sheet instead of the global:

Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Email").Set DataTable("Name", dtLocalSheet)
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebEdit("Passwd").SetSecure DataTable("Pwd", dtLocalSheet)
Browser("Gmail: Email from Google").page("Gmail: Email from Google").WebButton("Sign in").Click

In QTP, you can parameterize values of:

  • Checkpoints.
  • Object properties for the selected step.
  • Operation arguments are defined for a selected step.
  • One or more properties of an object are stored in the local object repository in the Object Properties dialog box or Object Repository window.

The above is also an example of data driving a certain test. We will see how to parameterize using the other Parameter types in the next article.

=> Visit Here For QTP Training Tutorials Series

Was this helpful?

Thanks for your feedback!

Recommended Reading

  • Techniques for Parameterization

    In part 1 of this QTP Parameterization tutorial, we explained Datatable Parameterization with an example. In this QTP tutorial let’s focus on the remaining three Techniques for parameterization in QTP: 2) Random number parameters 3) Environment variable parameters 4) Test/Action parameters => Click Here For QTP Training Tutorials Series #2 -…

  • QTP Tutorials

    Today we are publishing part one of a multi-part guest post series on Micro Focus Quick Test Professional (QTP). In this multi-part QTP training series we'll be covering all QTP tutorials and concepts in detail with adequate illustrations. Our expert author Swati S. will be helping us in bringing this…

  • FIND ELEMENT BY TEXT

    An In-Depth Look at Selenium Find Element by Text with Example: Selenium Find Element That Contains Specific Text Selenium Find element by text is used to locate a web element using its text value. The text value is generally used when the basic element identification properties such as ID or…

  • Using Virtual Objects and Recovery Scenarios

    Do you see an object not found error while running QTP tests? Well, this is because, during playback, QTP can’t recognize non-standard objects. To solve this object recognition problem, we use Virtual Objects. Using Virtual Object Wizard we can map these unrecognized objects to a standard class which can then…

  • Data Driven and Hybrid Frameworks

    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…

  • Using Text Area, Table, and Page Checkpoints

    In the last article, we were discussing the ways in which QTP can compare text. We also saw how standard checkpoints can be used to check the text and discussed the text checkpoint in detail. The next checkpoint is the Text area checkpoint. Let’s begin exploring it. => Click Here For…

  • Object Repository

    Object Repositories in QTP and Object Repository Manager This tutorial will focus on QTP Object Repositories. In our previous articles, we have discussed how QTP identifies and stores objects in a warehouse, the OR. We have also seen how the object properties appear in the OR. To quickly recap, we…

  • QTP Record and Run Settings

    This is the 6th QTP Tutorial in our QTP training series. As a reminder, we have started the QTP online training article series and we'll be covering almost all QTP tutorials with simple examples to understand the concept. => Click Here For The QTP Training Tutorials Series The last few QTP…


8 thoughts on “Parameterization in QTP Explained with Examples (Part 1) – QTP Tutorial #19”

  1. hello, thank you for the explanation, i wonder if it is possible in UFT to configure an INPUT Parameter as drop down list, it is to say, the INPUT Parameter will be a specific list of choices so that the user won’t set a wrong value which will not can be accepted later while the test is running
    best reagards

    Reply
  2. Hi Divya,
    “Run As Different User” wont work in QTP or UFT. Even if you login as a different user you will not able to identify the Objects in application which is signed in as different user.I did a lot of research on this and finally logged a HP ticket and they people told me like there is no solution for this. They took this input for their R&D purpose to add this enhancement for future versions of UFT….

    Thanks,
    Sandeep.
    9581641929

    Reply
  3. Verify informative articular.

    I have a script in which I need to write some values into data-table run-time.
    i.e.
    In flight application,After inserting an order some fields are populated with values.
    e.g. : Fight No, Departure Time, Arrival Time, Price etc.

    After running a script i want to add all these values in an excel and save, close it.

    Can I get some help? Thanks in advance

    Reply
  4. QTP – Tutorial #19 – suggested CORRECTION
    The main advantage of Parameterization is that it allows the use of a variety of test data to give good test coverage for the FUT (Functionality Under Test). It’s not the goal of using external data, parameterization, “to avoid duplicate test data”, which of course occurs anyway as a desirable by-product.

    Reply
  5. Great tutorial and helpful again.

    Following are the most common questions asked in interviews about this topic and I guess all these are answered in this tutorial:

    1) How does QTP handle input data variation?
    2) What is the use of Parameterization in QTP?
    2) What are the different types of Parameterization in QTP?

    Reply
  6. since third method is not successful for me i did setting changes for run on all rows.but only one row of data is running successfully.second row data was not taken before that itself the application closes.Is there any other settings have to be done in record and run settings.

    Reply

Leave a Comment