In this article we show the difference between the Global.DoWaitFor and Global.DoWaitForProperty synchronization functions.
Let’s consider an example. We have an application that is doing some initialization during load:
Finally, when initialization is done, the Proceed> button appears on the screen:
The sample test and application are available on GitHub.
DoWaitFor
Global.DoWaitFor is used when there is an object that may not exist on the screen before some point of time. In the AUT (application under test) we have a button Proceed>> that is not available until the app finishes loading. So here is how we can wait for the object:
RVL
JavaScript
/**
* Phase 1: Launch app, and wait using 'DoWaitFor'
*/
Global.DoLaunch("App\\LongLoadingApp.exe");
if(Global.DoWaitFor('Proceed__', 15000))
{
// We are here because DoWaitFor succeeded!
SeS('Proceed__').DoAction();
SeS('OK').DoLClick(49, 12);
Tester.Assert("DoWaitFor worked", true);
} else {
// We are here because DoWaitFor failed. DoWaitFor
// does not affect execution report, so in our case
// we need to report a failure explictly.
Tester.Assert("DoWaitFor worked", false);
}
// Kill AUT to start it again.
Global.DoKillByPid();
Please, note that the first parameter in Global.DoWaitFor represents an object by its Object Id.
The second parameter is a timeout to wait for.
If object is not found then DoWaitFor just returns false without writing anything to the report.
DoWaitForProperty
Global.DoWaitForProperty is used when there is an object that changes its state during the process and we need to wait for it to reach specific state. It may be progress bar or status message. In the considered application we have a Title (WindowText) that is visible all the time and finally it says Ready when the application is loaded:
So we wait for a specific value of the title, exactly what we do via Global.DoWaitForProperty:
RVL
JavaScript
/*
* Phase 2: Launch the same app, and wait using 'DoWaitForProperty'
*/
Global.DoLaunch("App\\LongLoadingApp.exe");
if(Global.DoWaitForProperty('LoadingForm', 'GetWindowText', 'Ready', 15000))
{
// We are here because DoWaitForProperty succeeded:
// title is now 'Ready'
SeS('Proceed__').DoAction();
SeS('OK').DoLClick(49, 12);
Tester.Assert("DoWaitForProperty worked", true);
} else {
// We are here because DoWaitForProperty failed. DoWaitForProperty
// does not affect execution report, so in our case
// we need to report a failure explictly.
Tester.Assert("DoWaitForProperty worked", false);
}
// Kill AUT to start it again.
Global.DoKillByPid();
Please, note that the first parameter in Global.DoWaitForProperty is an Object Id.
The second parameter is getter function name or action name (i.e .GetWindowText, DoGetText or whatever is available for the given type of object).
The third parameter is the expected value that we are waiting for.
The last parameter is the timeout (in milliseconds).
If the object is not present or didn’t reach required the state, the function simply returns false after the specified timeout without writing anything into the report.
DoWaitForProperty (Advanced Scenario)
By default DoWaitForProperty checks equality between actual and expected property value. If you need more complex condition use the callback function. In the example below we wait for window title to not start with word Loading.
To make it work both in RVL and JavaScript mode we define the callback in User.js file:
function CheckWindowTitle(value)
{
return value.indexOf("Loading") != 0;
}
RVL
JavaScript
/*
* Phase 3: Launch the same app, and wait using 'DoWaitForProperty'
*/
Global.DoLaunch("App\\LongLoadingApp.exe");
if(Global.DoWaitForProperty('LoadingForm', 'GetWindowText', CheckWindowTitle, 15000))
{
// We are here because DoWaitForProperty succeeded:
// title is now 'Ready'
SeS('Proceed__').DoAction();
SeS('OK').DoLClick(49, 12);
Tester.Assert("DoWaitForProperty worked", true);
} else {
// We are here because DoWaitForProperty failed. DoWaitForProperty
// does not affect execution report, so in our case
// we need to report a failure explictly.
Tester.Assert("DoWaitForProperty worked", false);
}
// Kill AUT to start it again.
Global.DoKillByPid();