Let us share some tips and tricks we come across when working with QTP.
If you want to share a New trick,add appropriate title in the "Post Subject" after clicking on the "New Reply" link.
Setting.Add trick to use run session values in next run sessions
Suppose you want to save some values manipulated in the run session somewhere so that you would like use them for next run session, the only ways(i think) are to save them to some external files like excel or output the values to global sheet.
I just went through the topic
"Setting Testing Options During the Run Session" which explains about
Setting.Add through which we can add some key value pairs more or less same like Environment variables
If you change the user defined Environment variables(pre-defined or dynamically created) in run time,they are all lost when the run session ends as they are reset to their original values and it can throw error if you try to use some dynamically created Environment variables of the last run !
So,the trick which i found is,
Just save your values in the form of 'key value pair' to Setting.Add "key","value"
which once created can be accessed in any run session thereafter.
Example of how to use it.
Now run this and see, first time you run, it will create a new setting item and next time you run, the message box promt will show the value.
Isn't it cool?
Note:These values will not be saved with the test after you close the test or open some other test(or create a new test)l!
If you want to share a New trick,add appropriate title in the "Post Subject" after clicking on the "New Reply" link.
Setting.Add trick to use run session values in next run sessions
Suppose you want to save some values manipulated in the run session somewhere so that you would like use them for next run session, the only ways(i think) are to save them to some external files like excel or output the values to global sheet.
I just went through the topic
"Setting Testing Options During the Run Session" which explains about
Setting.Add through which we can add some key value pairs more or less same like Environment variables
If you change the user defined Environment variables(pre-defined or dynamically created) in run time,they are all lost when the run session ends as they are reset to their original values and it can throw error if you try to use some dynamically created Environment variables of the last run !
So,the trick which i found is,
Just save your values in the form of 'key value pair' to Setting.Add "key","value"
which once created can be accessed in any run session thereafter.
Example of how to use it.
Code:
If Not Setting.Exists("IterNum") then
Setting.Add "IterNum", 1 'create "IterNum" and assign to 1
else
msgbox Setting.Item("IterNum") 'Use it or modify it as written below
Setting.Item("IterNum")=Setting.Item("IterNum")+1 ' modify "IterNum"
end if
Isn't it cool?
Note:These values will not be saved with the test after you close the test or open some other test(or create a new test)l!