Site Loader
Auckland, New Zealand
Wait is one of the most important operation in any automation testing tool, since we must/may need to wait for a control to fully appear in screen before performing further operations. Thread.Sleep can be used as opposed to Wait, but it’s always a bad practice to use it in code, since this will make our code to wait for time specified explicitly, even if the control appears or enabled on the screen, thread.sleep will make your code to wait for the time.
Side notes: In tool like Selenium, wait can be done using Implicit and Explicit wait as discussed in the article here
Coded UI on the other hand offers different types of wait methods which is shipped along with Visual Studio as shown below

Here is the complete video explanation of different wait methods in coded UI testing. Here is the complete code from the above video
public void WaitForControl(PropertyType type, string propertyvalue) where T : HtmlControl
{

    HtmlControl genericControl = (T)Activator.CreateInstance(typeof(T), new object[] { ParentWindow });
    if (type == PropertyType.Name)
        genericControl.SearchProperties[HtmlControl.PropertyNames.Name] = propertyvalue;
    else if (type == PropertyType.Id)
        genericControl.SearchProperties[HtmlControl.PropertyNames.Id] = propertyvalue;

    //Wait For the control
    genericControl.WaitForControlCondition(x => genericControl.WaitForControlPropertyEqual(type.ToString(), propertyvalue));

}

Thanks for watching the video and reading the article !!! Please leave your comments and let me know if there is anything needed to be improved in the post !!! Thanks, Karthik KK  

Post Author: Karthik kk

3 Replies to “Wait For Control in Coded UI Testing”

  1. Hi, This is a great set of videos. I am having a hard time figuring out the namespace for PropertyType.

    Cheers
    Tom

  2. Hi Karthik,

    How to increase default wait time of WaitForReadyTime. By default its value is 60 seconds, I want to change this to 120 or more .
    Please help me to do this if your aware of this.

    Regards,
    Divya

  3. Hi karthik, i would like to know why my recording break when it re uses the UIMap again . Also the control wont be ready in sometimes while running the scripts.
    Im working on WInforms c#

Leave a Reply to Divya Cancel reply

Your email address will not be published. Required fields are marked *