AIUtil Object

Note: In UFT 15.0, AI-based testing is supported for mobile testing only.

In UFT 15.0.1, desktop web support is added as a technical preview.

Description

A utility object for Artificial-Intelligence-based (AI-based) testing.

IMPORTANT

  • This object requires installing the UFT AI Features and enabling AI in the UFT options. For details, see the UFT Help Center.

  • Use AIUtil to access all the AI functionalities.

    Always use the SetContext method to set the context for AI operations before using any AI steps.

  • The AIUtil object has a default property, AIObject, this which returns an AIObject Object.

    You can therefore omit the word AIObject in the syntax using statements such as this one to access AIObject's methods and properties:

    'Click on the hamburger menu.
    AIUtil ("hamburger_menu").click
    

Operations

The sections below list the built-in methods and properties that you can use as operations for the AIUtil object.

Property AIObject Creates an AIObject for the specified control. The control can be specified by type, and for some control types, by the object text.
Property FindText Creates an AITextObject object for the specified text. This may be partial text within a larger block of text.
Property FindTextBlock Creates an AITextObject object for the specified text block.
Property IsMobileContext

Indicates whether the AIUtil context is currently on a mobile device.

Supported in UFT versions 15.0.1 and later.

Method SetContext Sets the top-level test object in which to use AI.

 

AIObject Property

Description

Creates an AIObject Object for the specified control. The control can be specified by type, and for some control types, by the object text.

If there are multiple similar objects on one page in the application, use the object's relative location in the application to describe it uniquely.

Syntax

One of: 

object ControlType, [AIText], [locator], [locatorData]

object.AIObject ControlType, [AIText], [locator], [locatorData]

Arguments

Parameter Description
ControlType Required. A String value.
The type of the control. For a list of supported control types, see the UFT Help Center.
AIText

Optional. A String value.
The text to use to identify the control. For a list of control types that support recognition by text, see the UFT Help Center.
Enter the micNoText constant if you want to ignore this parameter and provide values for locator and locatorData.

locator

Optional. A predefined constant or string value. Mandatory if you specify a value for the locatorData parameter.

Used to describe the unique location of an object that may appear multiple times in the application. The location can be ordinal, relative to similar objects in the application, or proximal, relative to a different AI object, considered an anchor.

  • For ordinal location, the locator represents the direction in which to count.

    Possible values: 
    Strings: "FromTop""FromLeft", "FromRight", "FromBottom".
    Constant values: micFromTopmicFromLeft, micFromRight, micFromBottom.

  • For proximity to a different AI object, the locator represents the direction of the anchor object.
    Possible values: 
    Strings: "WithAnchorOnLeft", "WithAnchorOnRight", "WithAnchorAbove", "WithAnchorBelow".
    Constant values: micWithAnchorOnLeft, micWithAnchorOnRight, micWithAnchorAbove ,micWithAnchorBelow.
locatorData

Optional. An Integer value or an AI object. Mandatory if you specify a value for the locator parameter.

  • For ordinal location, the locatorData provides the ordinal number of the object, starting with 1 for the first object.
    UFT counts the objects that match the description, in the direction specified in the locator parameter.
  • For proximity to a different AI object, the locatorData specifies the AI object to use as an anchor.
    The anchor must be an AI object (AITextObject Object or AIObject Object) that belongs to the same context as the object you are describing.
    The anchor can also be described by its location.
    UFT returns the AI object that matches the description and is closest and most aligned with the anchor, in the specified direction.

Return Type

An AIObject Object.

IMPORTANT

The AIObject property is the default property for the AIUtil object.

You can therefore omit the word AIObject in the syntax, and perform AIObject methods directly on the returned object within the same statement, as you can see in the example below.

UFT 15.0: 

  • The locator and locatorData parameters are named Orientation and Occurrence, respectively.
  • AI objects can be located by their ordinal location only, not their proximity to other AI objects.

Example

Back to top

FindText Property

Description

Creates an AITextObject Object for the specified text. This may be partial text within a larger block of text.

If there are multiple similar objects on one page in the application, use the object's relative location in the application to describe it uniquely.

Syntax

object.FindText AIText, [locator], [locatorData]

Arguments

Parameter Description
AIText

Required. A String value.
The text to find.

locator

Optional. A predefined constant or string value. Mandatory if you specify a value for the locatorData parameter.

Used to describe the unique location of an object that may appear multiple times in the application. The location can be ordinal, relative to similar objects in the application, or proximal, relative to a different AI object, considered an anchor.

  • For ordinal location, the locator represents the direction in which to count.

    Possible values: 

    Strings: "FromTop""FromLeft", "FromRight", "FromBottom".

    Constant values: micFromTopmicFromLeft, micFromRight, micFromBottom.

  • For proximity to a different AI object, the locator represents the direction of the anchor object.
    Possible values: 
    Strings: "WithAnchorOnLeft", "WithAnchorOnRight", "WithAnchorAbove", "WithAnchorBelow".
    Constant values: micWithAnchorOnLeft, micWithAnchorOnRight, micWithAnchorAbove ,micWithAnchorBelow.
locatorData

Optional. An Integer value or an AI object. Mandatory if you specify a value for the locator parameter.

  • For ordinal location, the locatorData provides the ordinal number of the object, starting with 1 for the first object.
    UFT counts the objects that match the AIText parameter, in the direction specified in the locator parameter.
  • For proximity to a different AI object, the locatorData specifies the AI object to use as an anchor.
    The anchor must be an AI object (AITextObject Object or AIObject Object) that belongs to the same context as the object you are describing.
    The anchor can also be described by its location.
    UFT returns the AI object that matches the AIText parameter and is closest and most inline with the anchor, in the specified direction.

Return Type

An AITextObject object.

IMPORTANT

UFT 15.0: 

  • The locator and locatorData parameters are named Orientation and Occurrence, respectively.
  • AI objects can be located by their ordinal location only, not their proximity to other AI objects.

Example

Back to top

FindTextBlock Property

Description

Creates an AITextObject Object for the specified text block.

If there are multiple similar objects on one page in the application, use the object's relative location in the application to describe it uniquely.

Syntax

object.FindTextBlock AIText, [locator], [locatorData]

Arguments

Parameter Description
AIText

Required. A String value.
The text block to find.

locator

Optional. A predefined constant or string value. Mandatory if you specify a value for the locatorData parameter.

Used to describe the unique location of an object that may appear multiple times in the application. The location can be ordinal, relative to similar objects in the application, or proximal, relative to a different AI object, considered an anchor.

  • For ordinal location, the locator represents the direction in which to count.

    Possible values: 

    Strings: "FromTop""FromLeft", "FromRight", "FromBottom".

    Constant values: micFromTopmicFromLeft, micFromRight, micFromBottom.

  • For proximity to a different AI object, the locator represents the direction of the anchor object.
    Possible values: 
    Strings: "WithAnchorOnLeft", "WithAnchorOnRight", "WithAnchorAbove", "WithAnchorBelow".
    Constant values: micWithAnchorOnLeft, micWithAnchorOnRight, micWithAnchorAbove ,micWithAnchorBelow.
locatorData

Optional. An Integer value or an AI object. Mandatory if you specify a value for the locator parameter.

  • For ordinal location, the locatorData provides the ordinal number of the object, starting with 1 for the first object.
    UFT counts the objects that match the AIText parameter, in the direction specified in the locator parameter.
  • For proximity to a different AI object, the locatorData specifies the AI object to use as an anchor.
    The anchor must be an AI object (AITextObject Object or AIObject Object) that belongs to the same context as the object you are describing.
    The anchor can also be described by its location.
    UFT returns the AI object that matches the AIText parameter and is closest and most inline with the anchor, in the specified direction.

Return Type

An AITextObject Object.

IMPORTANT

UFT 15.0: 

  • The locator and locatorData parameters are named Orientation and Occurrence, respectively.
  • AI objects can be located by their ordinal location only, not their proximity to other AI objects.

Example

Back to top

IsMobileContext Property

Supported in UFT versions 15.0.1 and later.

Description

Indicates whether the AIUtil context is currently on a mobile device.

Syntax

object.IsMobileContext 

Return Type

Boolean

True. If the current AIUtil context is a Device object, or a Browser object on a mobile device.

False. If the current AIUtil context is a desktop web Browser.

IMPORTANT

If your AIUtil context is a top-level Browser object, it may be a desktop web browser or a mobile web browser.

Some methods, such as Hover, are supported only on desktop web browsers. Before performing such an operation, use IsMobileContext to make sure the current AI context is a desktop web browser.

Designing your test this way makes it easier to use the same test for your web application on various platforms.

Example

Back to top

SetContext Method

Description

Sets the top-level test object in which to use AI.

Always set the AI context before using any AI operations.

Syntax

object.SetContext AIContext

Arguments

Parameter Description
AIContext Required. A top-level test object.
The top-level test object to use for the context.

Return Type

None.

IMPORTANT

UFT 15.0: The AI context must be a mobile Device test object that exists in your object repository.

UFT 15.0.1 or later: The AI context can be one of the following: 

  • A mobile Device test object stored in your object repository.

  • A web Browser test object stored in your object repository or described using descriptive programming.

    The web Browser can run on a Desktop or Mobile device, and be opened manually or from the Record and Run settings.

Example

Back to top