NameMapping – Conditional Mode

October 7th, 2013 by Bill Echlin

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.

ObjectNameMappingwindow

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.

object-name-mapping

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
selected-properties-in-windows-xp

You may also use the following script to refer to this log-in window.

mapped-name-of-login-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).

conditional-mode-of-NameMapping

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:

  1. Open the Object Name Mapping window of that object. Click on Conditional Mode button.
  2. ObjectNameMapping-1-1

  3. The Object Name Mapping window will be displayed in conditional mode as in the image below, with the selected properties.
  4. property-selected-inobjet-name-mapping

  5. Select the row of a particular property and click AND or OR button. (For above example select the row of wndClass and click OR)
  6. select-property

  7. TestComplete will show a new row as in the screenshot below.
  8. new-row-OR-condition-added

  9. In this new row, select the cell in the Property column and click on the ellipse button.
  10. select-this-cell
  11. 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)
  12. edit-property
  13. Select a condition type in the Condition column. (From the above example, select Equals)
  14. select-condition
  15. Select the cell in the ‘Value’ column and click on the ellipse button.
  16. select-value

  17. 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)
  18. adding-value-to-each-field
  19. In this example, we have added two wndClass values with the OR condition. Now this name mapping will work in XP and Windows 7.
  20. two-values-added-for-wndClass

  21. In the same way you can add multiple values for wndClass with the OR condition.
  22. windows-class-for-each-os

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.

Free Test Automation Framework Course
Learn the Practical steps to building an Automation Framework. Six modules, six emails (each email a short course in it's own right) covering Amazon AWS, Jenkins, Selenium, SoapUI, Git and JMeter.
Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *