Creating property checkpoints

The pith and marrow of any testing lies in the execution of various kinds of checks. In this recipe we will come to grips with the simplest type of checks: property checkpoint.

This means that for a selected object we check the value of a certain property (for example, text, availability, visibility, and so on).

Getting ready

Launch the Calculator Plus application (C:Program FilesMicrosoft Calculator PlusCalcPlus.exe).

How to do it...

In order to create a property checkpoint we need to perform the following steps:

  1. Begin recording of the script (go to Test | Record | Record Script menu).
  2. Switch to the Calculator Plus window and calculate some mathematical expression, for example, 2+7.
  3. On the Recording pane, in the Create New Property Checkpoint drop-down menu, go for the Create Property Checkpoint option.
    How to do it...

    As a result, the Create Property Checkpoint window will show up on the screen.

  4. Drag-and-drop the target icon on the results field in the Calculator Plus application, and release the mouse button. In the result, the Object field will contain the full name of the element for which the check will be carried out, as its screenshot appears in the Preview field.
    How to do it...
  5. Click on the Next button.
  6. On the Select a object property to compare panel, select the property wText and click on Next.
    How to do it...
  7. In the Specify comparison settings panel, among the comparison settings, opt for the Equals option in the Condition drop-down, and click on the Finish button.
    How to do it...
  8. Now, click on the Stop button in the Recording panel.
  9. In the result, in the TestComplete editor, we will obtain the following code:
    function Test1()
    {
      var wndSciCalc;
      wndSciCalc = Sys.Process("CalcPlus").Window("SciCalc", "Calculator Plus");
      wndSciCalc.Window("Button", "2").ClickButton();
      wndSciCalc.Window("Button", "+").ClickButton();
      wndSciCalc.Window("Button", "5").ClickButton();
      wndSciCalc.Window("Button", "=").ClickButton();
      var field = wndSciCalc.Window("Edit", "", 1);
      aqObject.CheckProperty(field, "wText", cmpEqual, "7, ");
    }

    Tip

    We have changed the generated code a little to make the code more readable.

  10. If we would launch the function, the log will have a notification, generated by the method CheckProperty. When the message is selected in the log, on the Additional Info tab, we would see the detailed description of the checkpoint.
    How to do it...

How it works...

In the first several lines of code, we simply click on the buttons. The check itself is executed by the method aqObject.CheckProperty, in which function call was properly generated for us by the wizard.

The method CheckProperty receives four parameters:

  • Object: This is an object, that would undergo the testing.
  • Property: This is the property that is being verified.
  • Condition: This is the type of the test. In our case, we have used exact comparison (the Equals type); however, it is also possible to use other types. For example, for the line, it is possible to check if a substring matches the line, and if it begins or ends with a specifically signified substring. For digits, one could apply fewer types of comparison. Altogether, there are about 16 types of tests.
  • Value: This is the value itself that is expected to be obtained as a result of the check.

If the test fails, the log will contain substantial information on the possible reasons for the errors.

How it works...

There's more...

Apart from the method aqObject.CheckProperty there is a similar function aqObject.CompareProperty. The difference is in the accepted parameters: the CompareProperty method takes property as a parameter and it's not the object or the property as in case of the CheckProperty method. Moreover, the CompareProperty method has another parameter, MessageType , which allows it to assign, which type of message will be generated in the event of a failure (an error, a warning, or an ordinary notification).

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

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