How to get current iteration number of QTP script?

How to get current iteration number of QTP script?

QTP test can run several iterations.
By default, when you run a test with global QTP Data Table parameters, QuickTest runs the test for each row in the Data Table, using the parameters you specified.

For example, the following global QTP Data Table contains 3 rows:

The iteration number of QTP test can be specified in 'File/Settings.../Test Settings dialog', 'Run' tab:

If we run our QTP test with above settings (global DataTable & 'Run' tab), the test will pass 3 iteration.
So, the question is How to determine the current iteration number withing QTP script?

Answer: We can use the value of "TestIteration" environment variable - Environment("TestIteration").

This is a sample QTP script I use to demonstrate Environment("TestIteration"):
str = "Current QTP iteration: " & Environment("TestIteration") & vbNewLine & _
"Param1: " & DataTable("Param1", dtGlobalSheet) & vbNewLine & _
"Param2: " & DataTable("Param2", dtGlobalSheet)

MsgBox str
And the result of above QTP script is:

As you can see, QuickTest Professional script works correctly.
You can use this approach to determine the current iteration number of running QTP script.


Related articles:


Have you got interested materials or your own thoughts on QTP (QuickTest Professional)?
Let's share them and help each other to improve our skills and knowledge!
You can send them to my email: Dmitry Motevich's email

Thank you in advance, dear readers.

--
Dmitry Motevich

2 comments:

Italiano said...

Hi Dmitry,

I'm having a problem to get the status(pass or fail) during runtime for every iteration ran, and must get the results stored to an excel sheet if possible.

Regards
Colin

Dmitry Motevich said...

@Italiano,
Please send your QTP questions to QTP Google Group