Working with Unsupported Controls - Text Recognition Technology
When testing software, you may need to get access to certain elements of an onscreen control or window (for example, menu items or grid cells). TestComplete 7 detects the type of each control you are using in your application. If there is special support for a control in TestComplete, the test engine provides special testing properties and methods so you can obtain the control’s data and simulate user actions over the control.
To recognize the control type, the test engine uses the object’s class name, application type, values of certain properties and other information. TestComplete supports a lot of different types of controls currently on the market. This support means that you can use specific methods and properties to work with these controls. If a control is not supported by TestComplete, you cannot use these specific methods and properties to work with the control. Testing objects that correspond to these controls only contain general methods for simulating user actions. However, some controls (like labels in black-box applications or cells of non-supported grid controls) may not be recognized as objects and your automated tests will not be able to work with them as they can with individual objects. For instance, you may be able to simulate a click over the grid, but not over an individual cell.
TestComplete’s Text Recognition technology provides a solution to this problem. The Text Recognition subsystem recognizes objects (labels, menu item, grid cells) by their text and creates the appropriate testing objects that let you simulate user actions over these objects and obtain the object’s text.
For instance, we enabled Text Recognition for a TdxBarControl in a sample application that is shipped with TestComplete. This control type is not officially supported by TestComplete. With Text Recognition, the menu items are recognized by TestComplete as
TextObjects and you can now simulate user actions like clicking an item. The following picture demonstrates a sample application that uses a TdxBarControl:
With Text Recognition, you can click the File menu item using the
Click method, which is available in the TestComplete Object Browser:
As you can see from the image above, there are a lot of methods that are made available by the Text Recognition technology. You can also switch to the Properties tab in the Object Browser and see the different properties available for testing your control, for instance, the
Height properties. TestComplete’s Text Recognition technology lets you use any of the listed methods and properties in your automated tests even for controls that are not officially supported.
How to Enable Text Recognition for a Control
In order to use the Text Recognition technology in your automated tests, make sure that you have the Text Recognition plug-in installed and enabled in TestComplete. To do this, choose File | Install Extensions from TestComplete’s main menu and search for the plug-in in the ensuing Extensions dialog.
To recognize a particular control, specify its class name in the project properties. For instance, to work with the TdxBarControl controls via the Text Recognition technology, follow these steps:
- Launch the tested application and find the control in TestComplete’s Object Browser panel.
- Find the WndClass property for your control in the Object Browser. In our case, it is “TdxBarControl”. Copy this value to the clipboard.
- Open the project editor and activate the Properties page. Find the Open Applications | Text Recognition settings group on the page.
- Add a new item to the list of accepted windows. Paste the class name from the clipboard. In our case, it is “TdxBarControl”.
- Save the changes made to the project.
Now, TestComplete will recognize the TdxBarControl objects and use the
TextObject method to address them. As the TdxBarControl is recognized, we can simulate a click over its items using the appropriate testing method, which was not available before.
How to Test Unsupported Controls
Suppose that an application’s main menu is created with a TdxBarControl control. TestComplete does not provide extended support for this control class, so automated tests do not have access to the menu items. Without Text Recognition, you can simulate a menu item selection by using coordinate-based clicks:
However, using coordinates makes your automated test less readable and it is a lot easier to break your automated test when changes are made to the application’s user interface. Also, it is often difficult or even impossible to find the item’s coordinates.
With TestComplete 7, instead of using coordinates, you can enable the Text Recognition technology for the TdxBarControl control to work around this problem. TestComplete will then recognize menu items by their captions, so you will be able to click the File menu item by using the
Click method of the
As you can see, this code is more readable and is made much more stable by using Text Recognition. This approach also makes your automated tests easier to create, since you don’t have to worry about coordinates. In a nutshell, TestComplete’s Text Recognition feature allows you to simulate user actions over any control with the same success that you experience over controls with built-in extended support.
If you are working with a control in TestComplete, and it does not have extended support by default, you can still work with it using TestComplete 7’s Text Recognition technology. This technology helps you identify the desired objects in the system and simulate user actions over it or retrieve the control’s text, making your tests more readable, stable and a lot harder to break when compared to using coordinate based testing approaches. If you haven’t tried TestComplete or if you want to try the Text Recognition technology, download and try it today for free.