Using Text Recognition Technology - Overview

Applies to TestComplete 14.30, last modified on November 21, 2019
Information in this topic applies to desktop applications only.

About the Text Recognition Technology

In your tests, you may need to get elements of an onscreen control or window (for example, menu items or grid cells) to simulate user actions on them or check their state. To get controls, TestComplete detects the type of each control in your tested application, and, if TestComplete supports the control, it automatically associates the control with a test object. For example, TestComplete associates standard Windows list views with the Win32ListView test objects.

Though TestComplete offers built-in support for many popular controls and components, it is still possible that it fails to recognize certain controls in your application. You will be able to test such controls only by using general methods and properties that TestComplete provides for onscreen objects. However, TestComplete may not recognize some objects, for example, labels or grid cells, at all, and you will not be able to work with them in your tests.

To test controls that TestComplete does not support, you can use the TestComplete Text Recognition technology.

Text Recognition traces text that the Operating System is drawing on the screen. TestComplete recognizes objects by the drawn text and associates TextObjects with them. You use properties and methods of those objects to work with controls in tests.

TextObject in the Object Browser

Let us explain this by citing an example. Let's suppose that a tested application has the TdxBarControl main menu. TestComplete does not provide extended support for this control class, and the test engine has no access to the menu items. You can simulate clicks on menu items by using coordinates:

w.Window("TdxBarControl", "MainMenu").Click(20, 10)

Using the coordinates makes it less readable and less resistant to changes made to the tested application’s user interface. In addition, it may be difficult (or impossible) to find the item’s coordinates.

To resolve this problem, you can use the Text Recognition technology.

In our example, TestComplete will recognize menu items by their captions. You will be able to click the File menu item by using the TextObject.Click method:

w.Window("TdxBarControl", "MainMenu").TextObject("File").Click()

Requirements

  • A license for TestComplete Desktop module.

  • The Text Recognition plugin that provides support for the Text Recognition functionality is installed and enabled by default.

    If you experience issues with text recognition, select File | Install Extensions from the TestComplete main menu and check whether the Text Recognition plugin is enabled.

  • The Text Recognition subsystem only catches the text that is drawn —

    • by the window procedure when it processes the WM_PAINT or WM_PRINTCLIENT message;

    • by functions of the Direct2D library.

    Text Recognition cannot recognize objects whose text is drawn in any other way.

Enabling Text Recognition for Your Application

To command TestComplete to use the Text Recognition functionality in your application, add the class name of your window or control to the Text Recognition | Accepted Windows list in your project:

  1. Right-click your project in the Project Explorer panel and then click Edit | Properties. This will open the Properties page of the project editor.

  2. Select Open Applications | Text Recognition from the list on the left of the page.

  3. Switch to the Accepted windows tab of the page.

  4. Click Add to add a new item to the list of accepted windows.

  5. Type the class name of your window (or onscreen control) and press Enter to confirm the change. (It must be the class name returned by the WndClass property of the object, to which your window or control corresponds.)

  6. Make sure the check box of the added item is selected.

  7. Choose File | Save from the TestComplete main menu to save the changes.

TestComplete will recognize text items of the specified window as TextObjects.

To access TextObjects from tests, use the TextObject method of the Window object.

Enabling Extended Text Recognition for Applications That Use Direct2D

TestComplete provides extended recognition for text rendered by using the Direct2D library (to learn more about the Direct2D library, see the Direct2D article in the MSDN Library). TestComplete can load its text recognition modules into a tested application and capture text that the Direct2D library’s functions render on the screen.

This way, TestComplete will be able to recognize text that it cannot recognize by using ordinary text recognition.

To command TestComplete to use the extended text recognition in your application:

Using extended text recognition may slow down the application performance and increase the memory consumption that, in its turn, may affect your tests.
  1. Add an application, whose controls you want to recognize by their captions, to the list of tested applications in your project. Otherwise, TestComplete will not be able to load its text recognition modules to your application’s process.

  2. Add the application’s process name to the Text Recognition | Extended support list in your project:

    • Right-click your project in the Project Explorer panel and then click Edit | Properties. This will open the Properties page of the project editor.

    • Select Open Applications | Text Recognition from the list on the left of the page.

    • Switch to the Extended support tab of the page.

    • Click Add to add a new item to the list.

    • Type the process name (for example, notepad or orders.exe) and press Enter to confirm the change.

    • Make sure that the check box of the added item is selected.

  3. Add the class names of windows or controls, whose text items you want to get, to the Text Recognition | Accepted windows list. See above.

  4. Run your application from TestComplete IDE or by using test commands. To learn how to do it, see Running Tested Applications.

TestComplete will launch your application and use the extended Text Recognition to recognize elements in specified windows or controls.

Specifics of the Text Recognition Technology

  • The TestComplete Text Recognition only can capture text displayed in the window’s client area.

  • If the text of a window element coincides with other (for example, grid cells have the same contents), TestComplete will use indexes to identify the object uniquely.

    An index depends on the element’s position on the onscreen control:

    • TestComplete assigns index 1 to the leftmost element of the window.

    • If elements have the same horizontal positions, TestComplete will index elements from top to bottom.

    For instance, the following image shows how TestComplete will index elements with the same caption:

    Indexing TextObjects

Samples

TestComplete includes a sample project that demonstrates how to use the Text Recognition functionality:

<TestComplete Samples>\Desktop\Orders\TextRecognitionService

Note: If you do not have the sample, download the TestComplete Samples installation package from the support.smartbear.com/downloads/testcomplete/samples/ page of our website and run it.

See Also

Requirements
Using Text Recognition Technology - Tips for Applications That Use Direct2D
TextObject Method
Possible Alternatives to Optical Character Recognition

Highlight search results