Mapping custom control classes to standard ones

At times, in tested applications, there crop up controls elements that are unknown in TestComplete and therefore, are unworkable; although, externally, a controls element of the kind appears to be a standard one (for example, a text field or a list of elements). It happens because programmers create controls with custom names and TestComplete doesn't know how to work with them.

The simplest way to resolve this issue is to try to explain this to TestComplete: this class is in reality a standard one (to be more exact, has been inherited from its standard class). In such a situation, we would be working with such an element as if it were a standard one, meaning the one taken after by inheritance. Certainly, in this case, we cannot use the extended possibilities of the controls element in view, while at least, we could execute some standard actions with it. For this purpose, TestComplete has specific project settings, which are called Object Mapping.

Since creation of a similar controls element or search for existing application to a similar effect is quite a difficult task indeed, we are using a workaround: teaching TestComplete not to work with the standard controls elements in order to obtain the data from a controls element of an entirely different type.

In Calculator Plus application (as in the standard Windows calculator), the controls element of the SysLink class is being used. This element is visible if the menu item About is selected from the Help tab. The text this product is licensed under… is the element we are talking about. If one were to look up its properties in Object Browser, the wText property would stand out as containing the text and the parameters, Link and LinkCount, allowing for more information about the links within the element. This element is our "guinea pig".

Getting ready

First we need to remove the existing object mapping for the SysLink elements as follows:

  1. Open the properties of the project (right-click on the name of the project and navigate to Edit | Properties).
  2. On the toolbar to the right, go to the section Object Mapping.
  3. Unfold the controls element Win32 Controls and Windows in the tree to the right, and uncheck the flag from the controls element of SysLink, as shown in the following screenshot:
    Getting ready
  4. Now TestComplete has no idea about recognizing the SysLink controls elements.

How to do it...

In order to be able to recognize the SysLink elements as text fields we need to perform the following steps:

  1. Launch Calculator Plus and opt for the menu item About in the Help tab. The window About Calculator Plus will show up on the screen.
  2. Open up Object Browser and locate the controls element of the SysLink type inside the About window (this element is unique therein).
  3. Look up the property of this element on the panel to the right and make sure that none of them contain the text This product is licensed under….
  4. Open up project properties (right-click on the name of the project and navigate to Edit | Properties).
  5. On the panel to the right, go to the Object Mapping section.
  6. Open up the Win32 Controls and Windows controls element, and in it check the element Edit box.
  7. Click on the button Add Class Name and into the appearing new controls element input the name of the SysLink class, as shown in the following screenshot:
    How to do it...
  8. Again, open up Object Browser, make the right-click on the Sys element and opt for the Refresh All menu item.
  9. Locate the element of the SysLink type again in the tree of objects, and go through its properties. Now we have the wText property available, from which we could get a hold on the readable text, as shown in the following screenshot:
    How to do it...

How it works...

Usage of the Object Mapping is the simplest method to work with nonstandard controls elements in case they are inherited from the standard ones.

Usually, in the inherited controls elements, some standard methods and properties still remain, which can be resorted to in order to obtain all (or almost all) the necessary information. This is exactly what we have done in the example of the SysLink element: we have taught TestComplete to work with this element as with a text field.

In truth we are bereft of some of the possibilities that the former properties held (for example, in the previous-mentioned example, we are short of accessing the Link and LinkCount properties); nonetheless, quite often all of what's within reach is enough for creation of genuine test scripts.

There's more...

If Mapping has not been a real help, and you are still up against an unwieldy controls element, you will have to come up with some more advanced methodology, such as:

  • Writing an extension of your own (quite a complicated approach, usually requires help of the developers of the tested application)
  • Usage of the provide properties and methods of the controls element to make it workable
  • Usage of text recognition possibilities and optical recognition
  • Working with the element as with an image

See also

For more advanced ways of working with nonstandard controls refer the following recipes:

  • The Working with nonstandard controls recipe in Chapter 3, Scripting
  • The Using text recognition to access text from nonstandard controls and Using Optical Character Recognition (OCR) recipes
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.125.51