There is a way in C # Coded UI to wait for a control to be clickable

In coded ui, there is a way to wait for a control to exist with UITestControl.WaitForControlExist(waitTime);. Is there a way to wait for a control to exist? The best way I could come up with is to create an extension method as follows:

public static bool WaitForControlClickable(this UITestControl control, int waitTime = 10000)
    {
        Point p;
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        while (stopwatch.ElapsedMilliseconds < waitTime)
        {
            if (control.TryGetClickablePoint(out p))
            {
                return true;
            }
            Thread.Sleep(500);
        }
        return control.TryGetClickablePoint(out p);
    }

Is there a better way to do this? I am also looking for a way to do the opposite.

+5
source share
3 answers

So actually WaitForControlExists is a call to public WaitForControlPropertyEqual, something like:

return this.WaitForControlPropertyEqual(UITestControl.PropertyNames.Exists, true, timeout);

Instead, your assistant may call:

 public bool WaitForControlPropertyNotEqual(string propertyName,
                object propertyValue, int millisecondsTimeout)

In addition, as Kek points out, there is a public WaitForControlNotExist method.

, , , ( ):

 public static bool WaitForCondition<T>(T conditionContext, Predicate<T> conditionEvaluator, int millisecondsTimeout)

Thread.Sleep , , .

+3

, :

Playback.Wait(3000);

.

+1

There is a family of methods WaitForControl...(), including a method WaitForControlNotExist().

A complete set of these methods Wait...:

WaitForControlEnabled()
WaitForControlExist()
WaitForControlNotExist()
WaitForControlPropertyEqual()
WaitForControlPropertyNotEqual()
WaitForControlReady()

There are also methods WaitForCondition()and WaitForControlCondition()that can be used to expect more complex conditions.

0
source

All Articles