3. Visual Creation of Objects

Applies to TestComplete 15.64, last modified on June 12, 2024

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

Once we have created the classes in the previous step, we can create objects based on these classes. To create an object, we will need to create a variable that will hold a reference to the object. Variables are organized into several groups. You can either add a variable to the default group or create a new group.

We will start creating the object hierarchy with the topmost object that is based on the ClsNotepadTest class and then we will create other objects down the hierarchy.

To create a new object:

  1. Add the ODT project item to your test. For this purpose, use the Create Project Item dialog.

  2. Create a new group or choose an existing one. To create a group, right-click the ODT | Data item ODT editor or the Data item in the Data editor.

  3. Change the group name to TestSample. To do this, either right-click the group name in the ODT or Data editor and select Rename from the context menu, or choose the group name and press F2. Then you will be able to type the new name.

  4. Right-click the created group name in the tree view in the ODT or Data editor and select New Item from the context menu. TestComplete will create a new variable and call it NewVariable. Change the name to ReleaseTest.

  5. From the drop-down list of the Value column, select (ClsNotepadTest). This means that the variable will hold a reference to the object based on the ClsNotepadTest class.

  6. The properties of the ClsNotepadTest class will appear as child nodes of the ReleaseTest object’s node:

Now we can configure the object properties even further:

  1. Use the ID property to specify the name of the test. To modify the property value, simply right-click the property, select Edit from the context menu and enter the desired value into the Value column. Enter ReleaseTest as the value of this property.

  2. The Files property of the ReleaseTest object holds an array of testing objects for each file to be used in our test. Let’s add one item to the array:

    • Right-click the Files node and select New Item from the context menu. TestComplete will create a new array item.

    • Select (ClsFile) from the drop-down list of the Value column for the new array item. The properties of the ClsFile class will appear as child nodes of the Item0 object’s node.

    • In the Path property of Item0, specify file1.txt. This means that the file will be located in the folder of the current TestComplete project, that is why we do not specify the full path to the file, only its name.

    • The Operations property of Item0 holds the array of testing objects for each operation that will be performed with the file1.txt file. Let’s add three items to the array as we are going to use three operations for this file.

      • Right-click the Operations node and select New Item from the context menu. This will create a new array item.

      • Select (ClsOperation) from the drop-down list of the Value column for the new array item. The properties of the ClsOperation class will appear as child nodes of the Item0 object’s node.

      • In the ID property of Item0, specify TimeDate.

      • In the MenuPath property of Item0, specify Edit|Time/Date. This is how the desired operation (insertion of date and time) can be accessed via Notepad’s menu.

      • We will leave the array of the Values property empty, because the chosen operation does not use any parameters.

      • Select the Item0 object variable and switch to the Methods page. It will list the Execute method the object got from its class, ClsOperation.

      • Right-click somewhere on this page and select New Item from the context menu. This will create a new method and call it NewObjectMethod. This method belongs exclusively to the particular object; it will not be inherited by the other instances of the same class.

      • Rename the method to Check and specify MainUnit.ClsOperationTimeDate_Check as its script routine.

      • Return to the Properties page, right-click the Operations node again and select New Item from the context menu. This will create the second array item, Item1.

      • Like the first array item, specify (ClsOperation) as the type of the second array item. The properties of the ClsOperation class will appear as child nodes of the Item1 object’s node.

      • In the ID property of Item1, specify Find.

      • In the MenuPath property of Item1, specify Edit|Find...; this is how the desired operation (searching for text) can be accessed via Notepad’s menu.

      • The Values property holds an array of objects that represent different sets of values for the given operation. We will create one value set (one array item).

        • Right-click the Values property of Item1 and select New Item from the context menu. This will create an array item.

        • Select (ClsFindData) from the drop-down list of the Value column for the new array item. The only property of the ClsFindData class will appear as a child node of the Item0 object’s node.

        • In the FindText property, specify aaa. This is the string we will look for in the file 1.txt file.

        • Using the same method, we will add the second and the third items to the Values array property and specify the bbb and ccc strings in their FindText properties correspondingly. These will be the additional variants of the string we will look for in file1.txt.

      • Now, we will create the third item (Item2) in the array of the Operations property. This item will represent the find-and-replace-text operation (ID will be set to FindReplace, MenuPath will be set to Edit|Replace...). The Values property will hold three array items of the ClsReplaceData type. The properties that each object of this class holds, FindText and ReplaceWithText, will be correspondingly set to aaa and bbb in the first item, bbb and ccc in the second item, and ccc and ddd in the third one. FindText is the string we will look for in the file and ReplaceWithText is the string that will replace the found string.

So far, in the object hierarchy of our test we have created a branch for one test file only. As much as object-driven testing is intended to operate with different sets of input data, which helps you diversify your tests, one file is not enough. To better illustrate the ODT practice, we will create several new file branches (array items in the Files array property). They will use different combinations of Notepad-related operations that are similar to those we have already mentioned. We are not going to cover the details on how to do this since it is similar to what you have just done.

TestComplete automatically creates new objects when you go down the object hierarchy on the Properties page of the ODT or Data editor. If you need to refer to an existing object that was created earlier, you should use a method that returns a reference to this object.

Prev     Next

See Also

Visual Creation of Custom Objects

Highlight search results