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.
OS
|
Class Name
|
windows 2003 | windClass3 |
windows 2008 | class8Wind |
windows XP | claswindXP |
Windows Vista | claswindvis |
Windows 7 | claswind7wind |
So we might be working on XP and while creating the Mapped name for this window we select the following properties.
wndClass | claswindXP |
wndCaption | New User |
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:
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.