AIObject Object
UFT One AI-based testing support:
UFT One version | Mobile apps | Desktop web |
---|---|---|
15.0 | Supported | Not supported |
15.0.1 | Supported | Technical preview |
15.0.2 | Supported | Supported |
DescriptionUFT One version support:
An internal object used to perform operations on an object recognized using AI.
IMPORTANT
AI objects are supported in UFT One only when:
- The UFT One Web Add-in or Mobile Add-in are installed and loaded.
- The UFT One AI Features are installed and AI is enabled in the UFT One options. For details, see the UFT One Help Center.
To retrieve an AIObject object, use the AIUtil.AIObject default property.
Operations
The sections below list the built-in methods and properties that you can use as operations for the AIObject object.
Methods
CheckExists | A checkpoint that checks whether the object currently exists in the set context. Supported in UFT One versions 15.0.2 and later. |
CheckState | A checkpoint that checks the state of the object. Supported in UFT One versions 15.0.2 and later. |
Click | Clicks the object. |
Highlight | Highlights the object in the application. |
Hover | Holds the cursor over the object. Supported in UFT One versions 15.0.1 and later. |
Search | Performs a search operation using an AIObject of type “Search”. |
Select | Selects an item from a combo box. Supported in UFT One versions 15.0.1 and later. |
SetState | Sets the state of a check box or toggle button to On or Off. |
Type | Types the specified string in the object. |
TypeSecure | Types the specified encrypted string in the object. |
Properties
Exist | Checks whether the object currently exists in the set context. |
CheckExists Method
Supported in UFT One versions 15.0.2 and later.
Description
A checkpoint that checks whether the object currently exists in the set context.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).CheckExists expected
Or
AIUtil(ControlType, [text], [locator], [locatorData]).CheckExists expected
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
expected | A Boolean value. Specifies whether this checkpoint expects the object to exist. Possible values: true. The checkpoint passes if the object is founds within the set context before the timeout expires. false. The checkpoint passes if the object is not found by the time the timeout expires. |
Remarks
This method uses the timeout defined in the Object Synchronization Timeout option in the Run pane of the Test Settings dialog box.
Return Type
A Boolean value.
Returns TRUE if the checkpoint passes, otherwise FALSE.
A TRUE return value reports a Passed step to the run results; a FALSE return value reports a Failed step to the run results.
Example
set ObjBrowser=Browser("creationtime:=0")
ObjBrowser.Highlight
ObjBrowser.navigate "https://www.advantageonlineshopping.com/#/"
AIUtil.SetContext ObjBrowser
AIUtil("profile").Click
'Check if clicking on profile worked
AIUtil("button", "SIGN IN").CheckExists true
AIUtil("input", "Username").Type "cdlsqa1"
AIUtil("input", "Password").TypeSecure "5e8febb7e9a9125c7611c19937e73b9696c9"
AIUtil("button", "SIGN IN").Click
wait 3'Check if clicking on SIGN IN button worked
AIUtil("button", "SIGN IN WITH FACEBOOK").CheckExists false
CheckState Method
Description
A checkpoint that checks the state of the object.
Supported in UFT One versions 15.0.2 and later.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).CheckState expectedState
Or
AIUtil(ControlType, [text], [locator], [locatorData]).CheckState expectedState
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
expectedState | A String value. Specifies the expected state of an object such as check box, radio button, or toggle. Possible values: On. The checkpoint passes if the object's state is ON. Off. The checkpoint passes if the object's state is OFF. Note: The state check is case insensitive. |
Return Type
A Boolean value.
Returns TRUE if the checkpoint passes, otherwise FALSE.
A TRUE return value reports a Passed step to the run results; a FALSE return value reports a Failed step to the run results.
Example
'The following example checks whether the Color check box is selected AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("Checkbox", "Color").CheckState On
Click Method
Description
Clicks the object.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).Click [x], [y]
or
AIUtil(ControlType, [text], [locator], [locatorData]).Click [x], [y]
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
x |
Optional. An integer value. The x-coordinate of the click. Note that the specified coordinates are relative to the upper left corner of the object. The default value is the middle of the object (-9999). |
y |
Optional. An integer value. The y-coordinate of the click. Note that the specified coordinates are relative to the upper left corner of the object. The default value is the middle of the object (-9999). |
Return Type
None
Example
'The following example clicks a point on the login button. AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("button", "Log In").Click 10, 10
Highlight Method
Description
Highlights the object in the application.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).Highlight
or
AIUtil(ControlType, [text], [locator], [locatorData]).Highlight
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Return Type
None
Example
'The following example draws a rectangle that flashes for a second around the identified check box AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("checkbox", "Select me").Highlight
Hover Method
Supported in UFT One versions 15.0.1 and later.
Description
Holds the cursor over the object.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).Hover [duration]
or
AIUtil(ControlType, [text], [locator], [locatorData]).Hover [duration]
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
duration |
Optional. An Integer value. The time period (in whole seconds) to hold the cursor over the object. Default: 2 seconds. |
Return Type
None
IMPORTANT
This method is supported only on Web applications running in a Web browser on a Desktop computer and not on mobile devices.
Before a Hover step, use the AIUtil.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
'The following example checks that the browser is not on a ' mobile device before performing a Hover step AIUtil.SetContext Browser("browser") 'Set the context for AI IsMobile = AIUtil.IsMobileContext If IsMobile = False Then AIUtil("menu").Hover AIUtil.FindText ("Clothing").Click 'Click the menu item displayed when hovering End If
Search Method
Description
Performs a search operation using an AIObject of type “Search”.
Syntax
AIUtil.AIObject("Search").Search [text]
or
AIUtil("Search").Search [text]
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
text |
Required. A String value. The string to enter in the search box. |
Return Type
None
IMPORTANT
The Search method is supported only for AIObjects of type "Search". The method enters the specified string in the search box and presses Enter.
Example
'The following example finds a search box on the mobile device 'and searches for the word "MyNewApp". AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("Search").Search "MyNewApp"
Select Method
Supported in UFT One versions 15.0.1 and later.
Description
Selects an item from a combo box.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).Select Item
or
AIUtil(ControlType, [text], [locator], [locatorData]).Select Item
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
Item |
Required. A String value. |
Return Type
None.
IMPORTANT
This method is supported for ControlType combo box, only in cases where UFT One can also identify this combo box as a WebList or a MobileDropDown.
Example
'The following example selects an item in a combo box. AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("combo box", "Color").Select "Blue"
SetState Method
Description
Sets the state of a check box or toggle button to On or Off.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).SetState State
or
AIUtil(ControlType, [text], [locator], [locatorData]).SetState State
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
State |
Required. A String value. Possible values: On, Off (case-insensitive) |
Return Type
None.
IMPORTANT
This method is supported for ControlType Toggle, Check box, and Radio button.
A radio button object represents one button in a radio group. Therefore, SetState on a radio button can only set the button to On. To set a radio button to Off, you must use SetState to set a different radio button in the group to On.
Example
'The following example selects a check box, by setting its State to On. AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("checkbox", "Select me").SetState "On"
Type Method
Description
Types the specified string in the object.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).Type [text]
or
AIUtil(ControlType, [text], [locator], [locatorData]).Type [text]
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
text |
Required. A String value. The string to type. |
Return Type
None
Example
'The following example types a user name in the edit box. AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("input", "USER NAME").Type "AIUser"
TypeSecure Method
Description
Types the specified encrypted string in the object.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).TypeSecure [text]
or
AIUtil(ControlType, [text], [locator], [locatorData]).TypeSecure [text]
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
text |
Required. A String value. The encrypted string to type. |
Return Type
None
IMPORTANT
To find the encrypted value to use as the argument for the TypeSecure method, use the Password Encoder utility (Start > All Programs > Unified Functional Testing > Tools > Password Encoder) or parameterize the argument and use the Data Table encryption option (right-click each unencrypted value in the password column and choose Data > Encrypt). For more information, see the Unified Functional Testing Help.
Note: While the TypeSecure method enables you to hide passwords on the screen when running a test, it is not intended to be a secure way to protect password information.
Example
'The following example types an encrypted password in the edit box. AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("input", "PASSWORD").TypeSecure "5cfe0d56013bbd8b5742b597cadc92352a6c"
Exist Property
Description
Checks whether the object currently exists in the set context.
Syntax
AIUtil.AIObject(ControlType, [text], [locator], [locatorData]).Exist([TimeOut])
or
AIUtil(ControlType, [text], [locator], [locatorData]).Exist([TimeOut])
Note: You can omit the AIObject property in the syntax, because AIObject is the default property for the AIUtil object.
Arguments
Parameter | Description |
---|---|
TimeOut | Optional. An unsigned long integer value. The length of time (in seconds) to search for the object before returning a True or False value.
Note: A value of 0 is not supported for Mobile test objects. For more information on the Object Synchronization Timeout, see the UFT One Help Center. |
Return Type
A Boolean value indicating whether the object exists.
Remarks
UFT One versions 15.0.2 and later: The Exist property can only be used in statements that use its return value. For example, assignment, print, and if statements.
Example
'This example checks whether a hamburger menu is displayed on the mobile device 'Set mobile device as current context. AIUtil.SetContext Device("Device") Dim objExist 'Check if the target object exists objExist = AIUtil("hamburger_menu").Exist if(objExist) then 'If exist report pass. reporter.ReportEvent micPass, "Found Obj", "Object exists" Else 'If not exist report failed. reporter.ReportEvent micFail, "Found Obj", "Object not exists" EndIf