Improve AI-based test object identification

Mobile, web, and windows-based SAP GUI tests

This topic discusses some of the elements that UFT One's Artificial Intelligence (AI) Features use to support unique identification of objects in your application.

Associate text with objects

The text associated with an object can help identify an object uniquely. For example:

AIUtil("input", "USER NAME").Type "admin"

Using the USER NAME text in this step to describe the object, ensures that we type in the correct field.

When detecting objects in an application, if there are multiple labels around the field, UFT One uses the one that seems most logical for the object's identification.

However, if you decide to use a different label in your object description, UFT One still identifies the object.

Example: When detecting objects in an application, a button is associated with the text on the button, but a field is associated with its label, as opposed to its content.

If a field has multiple labels and UFT One chooses one for detection, UFT One will still identify this field correctly when running a test step that uses a different label to describing the field.

In some cases, UFT One's AI combines multiple text strings that are close to each other into one text string to identify one object.

You can edit the combined string and leave just one to use for object identification. Make sure to remove a whole string and not part of it.

Example:  

For the text box below, UFT One's AI combines Password and Forgot? into one string to identify the object and adds the following step code to your test script:

AIUtil("text_box", "Password Forgot?").Type

You can remove a whole string from your script and change the code to the following without causing test failure:

AIUtil("text_box", "Password").Type

Back to top

Configure text recognition options

Customize these text recognition options to reach optimal text recognition on your application:

Text recognition in multiple languages

To enable UFT One's AI features to recognize text in languages other than English, select the relevant OCR languages in Tools > Options > GUI Testing > AI (or AI Object Detection). See AI Object Detection Pane (Options Dialog Box > GUI Testing Tab).

Exact text matching when identifying objects using AI

AI-based object identification uses AI algorithms for text matching. AI text matching may consider spelling variations and words with similar meaning to be matches.

If necessary, you can temporarily instruct UFT One to look exactly for the specified text when identifying AI test objects.

Add an AI run settings step to your test to set the text matching method. The setting is effective until you change it or until the end of the test run. For details, see the AIRunSettings Object in the UFT One Object Model Reference for GUI Testing.

Note:  

  • The text in the application is identified using OCR. If the OCR is inaccurate, AI text matching may be more successful than exact text matching.
  • Exact text matching is case-insensitive.

Use the UFT One text recognition settings

Instruct AI to use the UFT One text recognition settings. Depending on your UFT One configuration, this enables you to use Google or Baidu OCR cloud services or other UFT One OCR engines. See AI Object Detection Pane (Options Dialog Box > GUI Testing Tab).

Back to top

Use regular expressions

Supported in UFT One versions 2023 and later

When describing text to use for object identification, you can use a regular expression. This way, you can provide a pattern that the object's text should match, instead of specifying the exact text.

This helps identify dynamic text in your application, such as the total price in the shopping cart, or the number of items you have in your inventory.

To use a regular expression, use an AIRegex Object in the AIText parameter of the AIUtil.AIObject or AIUtil.FindTextBlock properties.

For details about the regular expressions supported in UFT One, see the Regular expression characters and usage options.

To make sure your regular expression identifies the right text, you can use the Tools > Regular Expression Evaluator. For details, see Regular Expression Evaluator.

Note: AI-based object identification uses Python regular expressions, while other UFT One features use VBScript regular expressions. For basic expressions, these should be similar. If the expression you create using the resources mentioned above does not meet your requirements, look into the details of Python regular expressions.

Example: When shopping on Amazon, we want to find the total price of our purchase, which appears twice on the shopping cart page, and looks like this:

The following test uses a regular expression to find this text and print it:

AIUtil.SetContext Browser("creationtime:=0") 'Set the context for AI
Set regex = AIRegex("Subtotal \(\d item\): \$[\d.]+")
print AIUtil.FindTextBlock(regex, micFromTop, 1).GetText	

When using regular expressions with micAIMatch, a certain level of deviation from the specified text pattern is accepted. Therefore, in the example above, the Subtotal string is returned even though it says 'items' in plural, and the regular expression has a singular 'item'.

Back to top

Identify objects by relative location

UFT One must be able to identify an object uniquely to run a step on the object. When multiple objects match your object description, you can add the object location to provide a unique identification. The location can be ordinal, relative to similar objects in the application, or proximal, relative to a different AI object, considered an anchor.

The AIUtil object identification methods now use location and locationData arguments in which you can provide information about the object's location. See AIObject, FindText, and FindTextBlock.

To describe an object's ordinal location

Provide the following information:

  • The object's occurrence, is it first, second, or third.

  • The orientation, the direction in which to count occurrences: FromLeft, FromRight, FromTop, FromBottom.

For example, AIUtil("button", "ON", "FromLeft", 2).Click clicks the second ON button from the left in your application.

To describe an object's location in proximity to a different AI object

Provide the following information:

  • The description of the anchor object.

    The anchor must be an AI object that belongs to the same context as the object you are describing.

    The anchor can also be described by its location.

  • The direction of the anchor object compared to the object you are describing: WithAnchorOnLeft, WithAnchorOnRight, WithAnchorAbove, WithAnchorBelow.

UFT One returns the AI object that matches the description and is closest and most aligned with the anchor, in the specified direction.

For example, this test clicks on the download button to the right of the Linux text, below the Latest Edition text block:

Set latestEdition = AIUtil.FindTextBlock("Latest Edition")
Set linuxUnderLatestEdition = AIUtil.FindText ("Linux", micWithAnchorAbove, latestEdition)
AIUtil("button", "download", micWithAnchorOnLeft, linuxUnderLatestEdition).Click

Note: When you identify an object by a relative location, for example, add a relation to the object in a recording session or in the AI Inspection window, the application size must remain unchanged in order to successfully run the test script.

Back to top

Describe a control using an image

If your application includes a control type that is not supported by AI identification, you can provide an image of the control that UFT One can use to identify the control. Specify the class name that you want UFT One to use for this control type by registering it as a custom class.

AIUtil.RegisterCustomClass "door", "door.PNG"
AIUtil("door").Click 

For more details, see the AIUtil.RegisterCustomClass method in the UFT One Object Model Reference for GUI Testing.

Once you register a custom class, you can use it in AIUtil steps as a control type:

  • AIUtil("<Myclass>")
  • AIUtil("<Myclass>", micAnyText, micFromTop, 1)
  • AIUtil("<Myclass>", micAnyText, micWithAnchorOnLeft, AIUtil("Profile"))

You can even use it to describe an anchor object, which is then used to identify other objects in its proximity:

AIUtil("profile", micAnyText, micWithAnchorOnLeft, AIUtil("<Myclass>") )

Note:  

  • You cannot use a registered class as an anchor to identify another registered class by proximity.
  • The image you use to describe the control must match the control exactly.

Back to top

Verify object identification

To increase the test run success rate, UFT One verifies the object identification before performing the operation. This is useful when objects in the application change locations during run time, for example, they are covered up by ads or scrolled to a new location. UFT One performs the operation on the new object location if it finds that the object moved.

If verification cannot locate the identified object, UFT One performs the operation at the location of the originally identified object. A warning message is displayed in the run result report.

By default, object identification verification is enabled for non-mobile contexts and disabled for mobile contexts. You can change the context settings in Tools > Options > GUI Testing > AI (or AI Object Detection).

Note: The added verification affects the speed of the test run.

To enable or disable object identification verification for a specific test run, use the AIRunSettings.VerifyIdentification object. See the AIRunSettings Object in the UFT One Object Model Reference for GUI Testing.

Back to top

Automatic scrolling

When running a test, if the object is not displayed in the application but the application screen is scrollable, UFT One automatically scrolls further in search of the object. Once an object matching the description is identified, no further scrolling is performed. Identical objects displayed in subsequent application pages or screens will not be found.

UFT One scrolls similarly when running a checkpoint that requires that an object not be displayed in the application. The checkpoint passes only if the object is not found even when scrolling to the next pages or screens.

By default, UFT One scrolls down twice. You can customize the direction of the scroll and the maximum number of scrolls to perform, or disable scrolling if necessary.

Note:  

  • You can also add steps within your test to actively scroll within the application. For details, see AIUtil.Scroll and AIUtil.ScrollOnObject in the UFT One Object Model Reference for GUI Testing.

  • UFT One versions 2021 R1 and later: When testing mobile apps, automatic scrolling is only supported when you work with Digital Lab (UFT Mobile) 2021 or later.

Back to top

Update local AI models

The AI Model Update feature is currently unavailable.

UFT One versions 2021 R1 and earlier:

You can open the AI > AI Model Update pane to see which model version you are currently using.

Back to top

See also: