Waiting for a property value

Sometimes, an application may be instrumental in a prolonged routine, during which the test should await its completion. Usually, an application prompts users upon completing the work. One of the examples of the completed operations state is a change of the property of the existing controls element (for example, the button Continue becomes enabled, background color is changed, and so on).

In this recipe, we will deal with a convenient know-how concerning waiting for the properties to be changed with the help of the WaitProperty method.

Getting ready

Launch Calculator Plus (C:Program FilesMicrosoft Calculator PlusCalcPlus.exe) and make sure it is started in either Standard or in Scientific mode. Make sure that the Digit grouping option from the View tab is unchecked.

How to do it...

Our task is inputting one and the same digit into the calculator (for example, the digit 2) until the value in the text output field is equal to 2222222.

  1. To make this happen, we will turn the following script to use:
    function testWaitProperty()
    {
      var expected = "2222222. ";
      var wCalc = Sys.Process("CalcPlus").Window("SciCalc", "Calculator Plus");
      var edit = wCalc.Window("Edit");
    
      wCalc.Activate();
      while(!edit.WaitProperty("wText", expected, 1000))
      {
        wCalc.Keys("2");
      }
    }
    How to do it...
  2. When the value in the text field becomes equal to the expected one, the function will stop working.

How it works...

Expected value contains an extra space character at the end of the string - this happens because the calculator applications add this space so that result wouldn't be too close to the right border of the text field. Users don't notice it, but TestComplete certainly does.

The method WaitProperty takes three parameters:

  • PropertyName: This parameter specifies the name of the property whose value is verified
  • PropertyValue: This parameter specifies the expected value
  • Timeout: This parameter specifies the maximal waiting time

If the property has gotten the expected value, the WaitProperty method returns true, otherwise, upon expiry of a set time frame, the method returns false.

This method is recommended for use instead of an ordinary delay (aqUtils.Delay) in the case that the completion of the monitored operation can be tracked by a given property of any of the controls element.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.123.73