Aim: Login to the sample flight application with multiple users
Excel File:
agentName Password
user1 mercury
user2 mercury
user3 mercury
user4 mercury
QTP Code:
datatable.Import "D:\QTP\TestData\login credentials.xls"
Dim i
Dim iRow
iRow = datatable.GetRowCount
For i = 1 to iRow
systemutil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set datatable.Value("agentName")
Dialog("Login").WinEdit("Password:").Set datatable.Value("Password")
Dialog("Login").WinButton("OK").Click
systemutil.CloseProcessByName"flight4a.exe"
datatable.SetNextRow
Next
QTP runs the script 16 times. The value of 'i' range from 1-4 and then is set back to 1. Why? Pointer should leave the for loop ideally. Can you please explain the reason?
Your script is probably set to "Run on all rows" which means it will run the script once for each row in the global data table. When executing, you are also looping through each row of the data table, so what you're doing is this...
Iteration 1
Loop 1
Loop 2
Loop 3
Loop 4
Iteration 2
Loop 1
Loop 2
Loop 3
Loop 4
Iteration 3
Loop 1
Loop 2
Loop 3
Loop 4
Iteration 4
Loop 1
Loop 2
Loop 3
Loop 4
That should be why you are seeing the script execute 16 times (4 x 4 = 16). Either set your script to run one iteration only or stop your script from internally looping the data table.