Tuesday 27 May 2014

Waiting for Application Object in CUIT (Coded UI Testing)

 
Well there are many situations where we end up with waiting for an object (AUT object like button, Textbox etc) to be enabled or visible or its property to change which we expect.

All these situations or synchronization needs Wait statement or method in our code.

In order to do that we can use Playback’s Wait statement, which has its internal thread to sleep for certain milliseconds specified.

Playback.Wait(5000);


Now the playback waits for 5000 milliseconds

Well there are some more wait methods available in Visual Studio 2010 Code UI testing which makes life of Automation test engineer easy. The following methods are

·         WaitForControlCondition

·         WaitForControlEnabled

·         WaitForControlExist

·         WaitForControlNotExist

·         WaitForControlPropertyEqual

·         WaitForControlPropertyNotEqual

·         WaitForControlReady


WinButton button = new  WinButton();
if
 (button.WaitForControlExist())
      Mouse.Click(button);

The following has the more details infomation of what exactly each method means


UITestControl.WaitForControlXXX() methods
Description
Waits for the control to be ready to accept mouse and keyboard input. The engine implicitly calls this API for all actions to wait for the control to be ready before doing any operation. However, in certain esoteric scenario, you may have to do explicit call.
Waits for the control to be enabled when the wizard is doing some asynchronous validation of the input by making calls to the server. For example, you can method to wait for the Next button of the wizard to be enabled (). For an example of this method, see Walkthrough: Creating, Editing and Maintaining a Coded UI Test.
Waits for the control to appear on the UI. For example, you are expecting an error dialog after the application has done the validation of the parameters. The time taken for validation is variable. You can use this method to wait for the error dialog box.
Waits for the control to disappear from the UI. For example, you can wait for the progress bar to disappear.
Waits for the specified property of the control to have the given value. For example, you wait for the status text to change to Done.
Waits for the specified property of the control to have the opposite of a specified value. For example, you wait for the edit box to be not read-only, that is, editable.
Waits for the specified predicate returns to be true. This can be used for complex wait operation (like OR conditions) on a given control. For example, you can wait until the status text is Succeeded or Failed as shown in the following code:
 
// Define the method to evaluate the condition 
private static bool IsStatusDone(UITestControl control) 
{ 
    WinText statusText = control as WinText; 
    return statusText.DisplayText == "Succeeded" || statusText.DisplayText == "Failed"; 
} 
 
// In test method, wait till the method evaluates to true 
statusText.WaitForControlCondition(IsStatusDone);
All the previous methods are instance methods of UITestControl. This method is a static method. This method also waits for the specified predicate to betrue but it can be used for complex wait operation (like OR conditions) on multiple controls. For example, you can wait until the status text is Succeededor until an error message appears, as shown in the following code:
 
// Define the method to evaluate the condition 
private static bool IsStatusDoneOrError(UITestControl[] controls) 
{ 
    WinText statusText = controls[0] as WinText; 
    WinWindow errorDialog = controls[1] as WinWindow; 
    return statusText.DisplayText == "Succeeded" || errorDialog.Exists; 
} 
 
// In test method, wait till the method evaluates to true 
UITestControl.WaitForCondition<UITestControl[]>(new UITestControl[] { statusText, errorDialog }, IsStatusDoneOrError); 

No comments:

Post a Comment