User Guide
Troubleshooting 25
■ Your scripts are failing in a spot where they should not be.
There are several solutions to these timing issues, which are described in the following
sections.
Adding waits to scripts
You can use the Wait statement to pause a script’s playback for any number of seconds. You
pass Wait(num_seconds) as an argument to the operation you want to pause in the script.
The following example waits 10 seconds before clicking the Milk FlexCheckBox control:
Browser("My Page").FlexApplication("MyApp").FlexCheckBox("Milk").Click
Wait(10)
For more information on using the Wait statements, see the QTP documentation.
Checking if objects exist
You can also check if the object exists before executing an operation on that control. To do
this, you can use the Exist statement. The following example checks whether the Milk
FlexCheckBox control exists before clicking on it:
If Browser("My Page").FlexApplication("MyApp").FlexCheckBox("Milk").Exist
Then
Browser("My Page").FlexApplication("MyApp").FlexCheckBox("Milk").Click
End If
You can also check for the value of the Exist common property on the control. For more
information on using the Exist statement or the Exist common property, see the QTP
documentation.
Slowing global playback times
You can configure QTP to play all events slower by setting a global execution delay. This
should be considered a last resort. You should first try to insert wait statements before
troublesome points in the test, as described in “Adding waits to scripts” on page 25. In very
large testing scripts, increasing the time it takes for each event to fire, even by a fraction of a
second, can dramatically increase the total run time of the test. Therefore, you should try to
find the lowest possible value that lets your scripts run correctly.
If you do choose to add a global delay, you should configure QTP to delay each step in your
script by some small number of milliseconds, and then gradually increase this amount until
you do not experience any errors.
To add a delay to each step in your test:
1. Select Tools > Options.