QTP/UFT tutorial- Parameterization the simple way 1(Importing Excel into QTp/UFT GLobal Sheet)

Hi. Some requests came in asking me how to parameterize a script. All parameterization is, is using multiple values for one variable. This technique saves time and gives you an opportunity to run more test cases with less code.

Example scenario: We want to test the login functionality with multiple user names but using the same script.

Follow the steps below:

1. Open a new test in QTP/UFT and save it as parameterization.

2. Open a new excel workbook

3. Name the worksheet in the workbook "TestData"

4. In cell A1 write UserNames

5. In cells A2, A3, and A4, write the names David, Bonnie, and Fred chronologically. See example below.

6. Save the workbook as "Example" in the same folder where you saved your QTP/UFT test. See example below.

7. Now close the workbook and go to your Parameterization QTP/UFT script. We will now import the sheet we just created into the QTP/UFT global sheet.

8. Copy and past the following code in your script:

dataTable.AddSheet "dtTestData"
dataTable.ImportSheet Environment("TestDir")&"\Example.xlsx", "TestData", "dtTestData"

First, we created a sheet in QTP "dtTestData"

Then we imported our Excel worksheet "TestData" into our newly QTP created shee "dtTestData"

The Environment("TestDir") holds the value of our directory where we save our QTP script/

Run this script and in the results, you will see that the sheet we created was successfully imported. Look at the value UserNames. This now became the column title in QTP/UFT.

9. Copy and paste the following code after importing the sheet:

dtSheerRowCount = DataTable.GetSheet("dtTestData").GetRowCount 

Dim i
For i = 1 To dtSheerRowCount Step 1
    varUserName = dataTable.value("UserNames", "dtTestData")
    MsgBox varUserName
    DataTable.SetNextRow
Next

Run the script and you will see the same variable prints 3 different names! The logic is explained below.

First, we get count of how many rows we have in our sheet. Since we created 3 user names, the count is 3.

Next, I set a variable to the equal our column value "UserNames" in our sheet "dtTestData". This way, QTP reads the user name directly from this column. By default, QTP starts at column 1.

Lastly, I created a for loop to loop through all of the user names. Once the name prints, we have to set the next row in QTP. We do this with the line DataTable.SetNextRow.

Congrats! You just parameterized your script! You can now take this simple example, and create a realistic scenario. Instead of just printing the User Names, you can enter these usernames in the application.

Pin It on Pinterest

Clef two-factor authentication