Using text recognition to access text from nonstandard controls

In some cases, if a controls element in the tested application has not been completely recognizable (for example, nonstandard toolbar), TestComplete can still provide us with access to some of the private properties of the element in view using the text recognition method.

In this recipe, we will consider usage of the text recognition method for accessing buttons on the toolbars in Paint application.

Getting ready

Launch a standard Paint Windows application (navigate to Start | All programs | Accessories | Paint).

How to do it...

In order to recognize text from controls we need to perform the following steps:

  1. Open up Object Browser and click through to the following element therein:
    Sys.Process("mspaint").Window("MSPaintApp", "Untitled - Paint", 1).Window("UIRibbonCommandBarDock", "UIRibbonDockTop", 3).Window("UIRibbonCommandBar", "Ribbon", 1).Window("UIRibbonWorkPane", "Ribbon", 1).Window("NUIPane", "", 1).Window("NetUIHWND", "", 1).
  2. The Window("NetUIHWND", "", 1) is the panel where the buttons are located; however, we have no possibility to work with these buttons, as the toolbar in view is not a standard one.
  3. Now, open the Project Workspace tab and pass on to project properties (right-click on the name of the project and navigate to Edit | Properties).
  4. Open up the group of options Open Applications – Text Recognition.
  5. Click on the Add button and add the class of NetUIHWND to the list of List of accepted windows.
  6. Include this class with the help of the checkbox near the name of the class and save the changes (press Ctrl + S) as shown in the following screenshot:
    How to do it...
  7. Again, open up the Object Browser and update the element of Window("NetUIHWND", "", 1), by right-clicking on it and opting for the Refresh All menu item.
  8. In the result, we will see several sibling objects that now are recognizable by TestComplete, as shown in the following screenshot:
    How to do it...

How it works...

If a nonstandard controls element uses a standard Windows API for text output, we could recognize the text within it with the help of Text Recognition method, as described.

With the elements of the TextObject type we can make ordinary actions (for example, triggering mouse-clicks on them, obtaining values of the properties, and so on); however, having no possibility to normally work with their parent objects. For example, in case of the Select button in Paint, we are getting access only to the text Select, and not to all the buttons with image. Nonetheless, these simple possibilities are usually sufficient for functional testing.

See also

  • Text Recognition is one of the simplest methods to work with nonstandard controls elements. If this approach could not help you cope the issue of elements recognition, it's time to turn to more sophisticated recipes. For this refer to the Using Optical Character Recognition (OCR) and Dealing with self-drawn controls not supported by TestComplete recipes.
..................Content has been hidden....................

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