Friday, 29 April 2016

Synchronization in Coded UI

About Synchronization:
Making sure that the speed of automation scripts execution should be in sync with application under test (AUT) response/speed
To enable synch,  Coded UI/QTP/.. Uses WAIT statement or Test Settings

Different levels of Sync:
Test level sync
          Default wait time is 60000 milliseconds
Statement level sync
          Unconditional wait – Playback.Wait
          Conditional wait – all other wait statements

Purpose of Wait statements:
A Wait statement can be used for:
          a web page to load
          a button to become enabled or disabled
          a client server communications to finish

Wait statements
The following wait statements  could be used to wait or suspend the execution until the specified time period is elapsed:

    Playback.wait()

      -  Waits for specific time period

      -  Default time could be  changed by using ‘WaitForReadyTimeout’ in Playback settings

Wait statements  on controls:
WaitForControlReady() – Waits for the control to be ready to accept keyboard or mouse input.

WaitForControlEnabled() – Waits for control to be enabled

WaitForControlExist() – Waits for control to exist on UI

          Example: Expecting a dialogbox after application has done validation of parameters

WaitForControlNotExist() – Waits till the control cease to exist on application

          Example: progress bar to go away

WaitForControlPropertyEqual (string propertyName, object propertyValue)

          Example: status text to change to Done

WaitForControlPropertyNotEqual (string propertyName, object propertyValue)

WaitForControlCondition – Could be used for a complex wait operation (OR operation) on a specific control

          Example: to wait until the status text is “Succeeded” or “Failed”
          Sample 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);

WaitForCondition – Could be used for complex wait operation (OR operation) on multiple controls

          Example: to wait until the status text is “Succeeded” or error dialog is displayed
          Sample 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);

For Free Demo Call me on Mobile/Email - 9597100592/vardhancuit@gmail.com
You can help yourself with more information from my website www.software-testing-zone.info
If you like the post, comment on the same.

No comments:

Post a Comment