Ask a Question

Wait on a UI refresh

Occasional Contributor

Wait on a UI refresh

We have a test that is expecting a DevExpress grid to contain one item, but it fails intermittently. 


It's all dependent on how fast the Web API responds with the list of items.


How can I instruct TestLeft to "wait a few seconds". Please note that the Window.TryFind() with a wait does not work, because the window is nearly immediately available, but the API call has not come back yet. We just need a few seconds of hold time to ensure the Web API call has returned before evaluating.

Champion Level 3



Regular TestComplete/TestExecute (TestLeft is based on their engine) has aqUtils.Delay(<timeout in ms>) method. You may use Object Spy in TestLeft, search for this method and call it. (Sorry, cannot provide you with the more detailed code at the moment.) Obviously, this is a quick and dirty way.

If your tested application allows it, my preference is like this:

-- get reference to the target grid (wait for it);

-- get its current number of (displayed) records;

-- in a loop, with some small delay (e.g. 500ms), for some timeout, wait until the number of records is greater than zero and does not change (which means that the grid has been populated with data).

  /Alex [Community Champion]
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
New Contributor

In the simplest case the following function might be used:


public static bool Wait(Func<bool> condition, int timeout)


    var end = DateTimeOffset.UtcNow.Add(TimeSpan.FromMilliseconds(timeout));

    while (DateTimeOffset.UtcNow < end)


        if (condition()) return true;



    return false;



Timeout variable defines here only the maximum timeout, if the condition is true, the execution will immediately continue (well, ok, it might take up to 200 ms Smiley Happy).


The call of the function might be something like:


if (!WaitHelper.Wait(() => UIMap.OpenButton.Enabled && UIMap.MachineComboBox.Enabled)


    Assert.Fail("After import the nesting properties are not loaded sucessfully");



Hope this helps.

Showing results for 
Search instead for 
Did you mean: