10-07-2009, 08:18 PM
I have to chime in here. I have not investigated timers in QTP yet, but I will. The difference between a While loop and a Wait statement is huge in my opinion.
While both options will get the required results, the difference is in the effect on the test system. A While Loop, Bansanth27's code withstanding because he uses a wait statment, will cause 100% CPU utilization during the loop. This may or may not affect your testing but it certainly can if you are waiting on an application that is utilizing resources heavily and can effect your timing of the application or test.
A Wait statment on the other hand is equivalent to the a .NET/VB Thread.sleep(). Your test application will actually go to sleep for the timeframe requested and have zero CPU utilization. I think this will give you better results in the long run if you are actually trying to measure an application performance.
Of course you need to remember there is no way to continue or break out of a wait statment. It will stay in effect for exactly how long you tell it to wait for. Bansanth27's code using a wait in a while gives a real world example of how to utilize the ability of the wait statement releasing resources for other applications as well as give it a conditional out.
While both options will get the required results, the difference is in the effect on the test system. A While Loop, Bansanth27's code withstanding because he uses a wait statment, will cause 100% CPU utilization during the loop. This may or may not affect your testing but it certainly can if you are waiting on an application that is utilizing resources heavily and can effect your timing of the application or test.
A Wait statment on the other hand is equivalent to the a .NET/VB Thread.sleep(). Your test application will actually go to sleep for the timeframe requested and have zero CPU utilization. I think this will give you better results in the long run if you are actually trying to measure an application performance.
Of course you need to remember there is no way to continue or break out of a wait statment. It will stay in effect for exactly how long you tell it to wait for. Bansanth27's code using a wait in a while gives a real world example of how to utilize the ability of the wait statement releasing resources for other applications as well as give it a conditional out.