We’ve mentioned in previous posts about Name Mapping in our software test automation tool TestComplete. Whilst creating a Mapped name for an object we select a few properties which we use to identify that object. This is the ‘Basic Mode’ of Name Mapping. In some cases though, the value of the selected property may differ. Perhaps in a different environment the properties are different.
For example, a window may have different class name in different OS. Sometimes you may want to give the value of the property within some range or with some condition. For example, Childcount > 34, or Name should start with the string “save”. To create name mapping with these conditions we have to use the Conditional Mode of Name Mapping.
By default, while creating a Mapped name for an object, TestComplete opens the Object Name Mapping window in Basic mode.
However, you can switch to conditional mode. You just need to click the Conditional Mode button at the bottom of the window. The conditional mode window will then look like this.
From this you can see that you can give combinations of properties with extended conditions.
Let us say there is a log-in window in a windows application. This window has a different class name in each OS as shown below.
So we might be working on XP and while creating the Mapped name for this window we select the following properties.
You may also use the following script to refer to this log-in window.
After developing the script for XP, if you try to execute the same code in Windows 7 it will not recognize the window object. TestComplete will log an error message “Object does not exist”. This is because in Windows 7 this window has the wndClass value as claswind7wind. This values is not equal to the value selected in Name Map. So by default our software test automation tool fails at this point of object identification.
To avoid this issue you could create multiple mapped names for this object on each OS. However, you would end up with a very long name map object tree. With conditional mode in NameMapping, you can simplify this and mention all the class names in a single mapped name (as shown below).
If we provide the conditions above then name mapping will work in any OS. So, the above mentioned script will then work in all the operating systems. The following section explains how to name map for this login window in conditional mode.
Steps to Create NameMapping in conditional mode:
- Open the Object Name Mapping window of that object. Click on Conditional Mode button.
- The Object Name Mapping window will be displayed in conditional mode as in the image below, with the selected properties.
- Select the row of a particular property and click AND or OR button. (For above example select the row of wndClass and click OR)
- TestComplete will show a new row as in the screenshot below.
- In this new row, select the cell in the Property column and click on the ellipse button.
- Our software test automation tool will invoke the Edit Property window. Select a Property from the Type combo box and click OK button. (From the above example select wndClass property)
- Select a condition type in the Condition column. (From the above example, select Equals)
- Select the cell in the ‘Value’ column and click on the ellipse button.
- This will invoke the Edit Value window. Select or enter the appropriate values in each field and click the OK button. (From the above example, use the values as in the image below)
- In this example, we have added two wndClass values with the OR condition. Now this name mapping will work in XP and Windows 7.
- In the same way you can add multiple values for wndClass with the OR condition.
Now in the above example, you can use the same code in all the operating systems. You will not need to make any changes to your code to manage the different operating systems. Our software test automation tool will recognize the window in all the OS using the single mapped name.
So the conditional mode reduces our effort and increases the testing productivity. We can make our script more adaptable. And since we no longer need to make any changes in the script, maintenance of our code becomes simpler.