Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C# Coded UI is there a way to wait for a control to be clickable

In coded ui there is a way to wait for a control to exist using UITestControl.WaitForControlExist(waitTime);. Is there a way to wait for a control to not exist? The best way I could think of is to create an extension method like this:

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 of doing this? Also I am looking for a way to do the opposite.

like image 389
jgerstle Avatar asked Apr 22 '13 13:04

jgerstle


People also ask

What does |= mean in C?

The ' |= ' symbol is the bitwise OR assignment operator.

What is '~' in C programming?

The ~ operator in C++ (and other C-like languages like C and Java) performs a bitwise NOT operation - all the 1 bits in the operand are set to 0 and all the 0 bits in the operand are set to 1. In other words, it creates the complement of the original number.

What is an operator in C?

C operators are one of the features in C which has symbols that can be used to perform mathematical, relational, bitwise, conditional, or logical manipulations. The C programming language has a lot of built-in operators to perform various tasks as per the need of the program.

What is the use of in C?

In C/C++, the # sign marks preprocessor directives. If you're not familiar with the preprocessor, it works as part of the compilation process, handling includes, macros, and more.


1 Answers

So what WaitForControlExists actually does is to call the public WaitForControlPropertyEqual, something like:

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

Your helper can instead call:

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

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

Note that they all seem to be using the same helper (also public):

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

this helper essentially does a Thread.Sleep on the current thread, pretty much as you do it.

like image 141
Bogdan Gavril MSFT Avatar answered Oct 23 '22 12:10

Bogdan Gavril MSFT