Sometimes, there is a need to suspend script execution for some time to allow for synchronization with the work of the application. In this recipe, we will deal with the simplest method to provide such a timeout.
In order to demonstrate the delay, we will use the Test1Modified2
function from the Modifying the recorded test recipe:
Test1Modified2
function by adding one line into it: for(var i = 0; i < aButtons.length; i++)
{
wCalcPlus.Window("Button", aButtons[i]).ClickButton();
aqUtils.Delay(2000);
}
Test1Modified2
, it will be apparent that upon each Calculator Plus button-click TestComplete will delay execution of the script at the rate of 2 seconds, and then continues with the flow of execution.The aqUtils.Delay
method pauses script execution for a specific range of milliseconds (for example, 2000
milliseconds equals 2 seconds).
This delay does not account for any factors (for example, CPU speed of the computer or network connectivity speed), which means one and the same delay can be too large or too small in different conditions. In first case, we will continually have errors in the log; while in the second case, scripts will have a useless standstill over the given period of time.
There's one case when usage of the method aqUtils.Delay
method is mandatory: when we expect a specific event in the loop to be triggered. Let's say we need to wait for the creation of the c:somefile.txt
file. In this case, the code will be as follows:
while(!aqFile.Exists("c:\somefile.txt")) { aqUtils.Delay(500, "Waiting for file..."); }
If the delay is not added to this code, TestComplete will keep checking too often, driving the CPU usage up to 100 percent, and thereby significantly slowing down work of other applications.
18.221.136.142