TestComplete 5 Sneak Peek: Name Mapping Improvements
Test and Monitor | Posted November 29, 2006

TestComplete 5 is currently under development, the information contained in this article is not final and may change at any time.

Automated UI testing is naturally vulnerable to changes made to the application's GUI under test. For instance, you record a script where a button is pressed, then the developers  make significant changes to the application adn the button. The button is now very different as well as the attributes of the window where the mouse is clicked. As a result, we can't expect the script will play back without modification. In this situation, the tester will have to make some manual corrections before starting the next test run.

Another issue to address is testing applications that support localization. Some of you may ask: "Will I have to rewrite my script to test the same functionality in another language?" No, you won't have to rewrite them. Using TestComplete's Name Mapping feature, you'll be able to solve this and many other problems. Name mapping allows you to assign custom names to different kinds of objects. Name Mapping can make your scripts logical and simpleeven if you don't come across these problems .

Here's an example: Suppose, you want to learn which URL is currently selected in Internet Explorer. One way to do this is to read the contents of Internet Explorer's Address box that is shown at the top of the browser window. To obtain the text in the Address box, you can use the following code:

Though the default naming concept adopted in TestComplete allows you to address the desired window, this code is pretty complex. With Name Mapping and assign logical names to the object, the code is simpler:

The mapped code string is much easier to read. However, this is not the end of Name Mapping. We've added the very useful Aliases feature which complements Name Mapping. An alias is an alternate object name that can be used like any other name. Now, if we use the Aliases program object, the code of the above-cited example will become even more concise and clear:

Aliases let you change the hierarchy of mapped objects and skip useless levels. You create an alias by dragging the desired name mapping item to the Aliases tree in the Name Mapping editor.

Readable code is not the only advantage of Name Mapping. We've created a configuration mechanism that makes testing of multi-language applications much easier. Below you can see how to use Name Mapping while testing multi-language applications.

For this purpose, we are going to test a C# application whose main window is in the figure below:

Click to display image

First, we need to map the buttons that reside on the form. To do this --

  • Switch to TestComplete's Object Browser.
  • Find the desired button in the object tree.
  • Right-click the button node and choose Map the Object Name from the context menu:

    Click to display image

TestComplete will ask you to map the whole hierarchy of the objects up to the selected button (this is a requirement of the name mapping concept). We will skip mapping parent objects and pay more attention to mapping the selected button, since this button's caption will be changed in a localized version of the application. The default recognition properties are in the figure below:

Click to display image

Since we want to identify the button only by its text, we should remove all other properties using the button in the properties window. We should only leave the Text property, and we also need to assign the button a readable name, for example, ButtonHelloWorld. We also map the other buttons in a similar fashion. Then the Name Mapping editor will look like:

Click to display image

TestComplete will add the NameMapping objects to the script during the recording. Here 's an example,  we've recorded a script that clicks the application buttons in sequence:

This automated test is robust and it won't fail if the buttons' position is changed, or if their size, or even the buttons' class names change, because we identify the buttons by their text. So, if a developer moves the buttons to another location or use components of a third-party vendor using the existing names, the script will remain functional. What should you do if the developers localize the application? In this case, you can make use of the NameMapping configuration mechanism.

Suppose you've a localized application in French and its main window is in the figure below (the position of the buttons has been changed to show that the script will remain functional even if the initial conditions are changed):

Click to display image

In the NameMapping editor, we press the Copy As New Configuration button at the top of the editor. TestComplete will ask you to enter the name of a new configuration (let's call it French Localization) and then copy the name mapping settings of the current configuration to the new one. You can switch to the configuration using the Configuration box in the NameMapping editor. You can also switch to configurations from scripts by using specific methods of the NameMapping object.

To run the script again, in the NameMapping editor, we need to correct the values that were used to map the objects. The figure below shows the dialog where you change the ButtonHelloWorld object's Text property value.

Click to display image

You can specify property values not only by entering constants, but also by referring to a project variable.

After we make corrections in the buttons’ Text fields, the script will become functional again.

TestComplete 5's Name Mapping plug-in make scripts more readable and robust. It also solves problems that often arise while testing localized applications. Finally, the fact that this process can be controlled from the TestComplete UI and within scripts makes this feature powerful and convenient.


By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox