Hi. Last time I showed you how to parameterize by importing an excel sheet into the global sheet within QTP/UFT. You can find the tutorial here. The set up for using excel is a bit longer but it pays off in the longer with little maintainability, and being to modify the values in excel instead of QTP/UFT. Today, I will show you how to parameterize directly within your script with minimum set up. This way takes a lot less effort to set up, but is not as dynamic or as easy to maintain as using an external data sheet.
Example: Let's say that you are testing the login functionality of an application. And let's say that you want to test this login functionality for three separate users. Now instead of creating three separate scripts for each of those users, you can use parameterization to consolidate those three scripts within one.
1. Wrap your full script within a for loop that would loop for the amount of users you would like to test with. In our example, we have 3 separate users, so our loop will loop 3 times.
For i = 1 To 3 Step 1
2. Set up the conditions for the parameterization. Ex. If the loop is on the first loop, then username1, else if the loop is on the second loop, use username2, and if the loop is on the third loop, use username3.
For i = 1 To 3 Step 1
If i = 1 Then
varUserName = "Johnny"
ElseIf i=2 Then
varUserName = "Suzie"
ElseIf i=3 Then
varUserName = "Fred"
3. Now run this script and you will see the same variable will show 3 different usernames. I made this tutorial to show you the simplest way of parameterization. Clearly, your scripts will be a bit more complex, but the idea of parameterization will remain the same. You did it! That's all there is to it. Set up a loop and set the conditions for the various user names you want to test.
Leave your comments and questions below. I love all of your feedback!!
Latest posts by Admin (see all)
- SQA QTP tutorial – WebList identified as a web element and how to select an item from this list - December 9, 2015
- Automation QTP tutorial-double clicking on any object - December 4, 2015
- Software Automation QTP tutorial – 5 top reasons for using automation - November 23, 2015