Add AI-based steps to your tests
Mobile, web, and windows-based SAP GUI tests
You can add AI-based steps to your test during an AI Object Inspection or AI Object Record session, or you can type them manually in the editor.
Note: This is part of a higher-level task. For details, see AI-based testing in UFT One.
Add a step to set the AI context
Before you can run any AI-based steps in your test, you must set the context in which to use AI.
The AI context is a UFT One test object of one of the following: Web Browser, mobile Device, or SAPGUISession.
Within this context, UFT One searches for objects using AI. You can set the AI context for your test in one of the following ways:
-
In the Live Application tab of AI Object Inspection window, add a SetContext step from the right pane, or click the down arrow near Context and select Add as "SetContext" step to test.
-
Manually add a SetContext step to your test before you add any other steps. This is necessary when you create a test script for application mockups.
-
A SetContext step is automatically added if you use AI Object Record to record a test.
UFT One must be able to identify the context object throughout the test run. If necessary, use additional SetContext steps to select a different object for the context.
Tip: Within a web browser context, you can also add AIUtil.Context.SetBrowserScope steps, to specify whether to inspect the whole browser for objects or only the web page itself. Inspecting the whole browser is useful when your test needs to respond to a pop-up dialog box that opens in the browser. Note that UFT One cannot identify any pop-up dialog boxes hidden behind the browser window.
Add steps when using AI Object Inspection
You can add step when inspecting a live application or application mockup images. If you are inspecting a live application, you can also run the added step on the application. This tests the step and advances the application to the next state.
To add a step to your test:
-
Do one of the following:
-
Inspect a page or screen of your open application in the Live Application tab of the AI Object Inspection window. See To identify all objects.
-
Inspect an image of you application in the MOCKUP IMAGES tab of the AI Object Inspection window. See Inspect application mockups for objects.
-
-
Click a highlighted object.
A pop-up dialog box opens with the suggested step and object description.
For details on running Select operations on combo boxes, see Supporting Select operations on combo boxes.
-
(Optional) Click Edit step to add additional object description properties including Position and Relation in the right pane.
-
You can specify properties that do not each uniquely describe the object. You can only add the step to your test if the combined description uniquely identifies the object. Otherwise, when you move to another object, your edits are discarded, and the original description is used.
-
When you add a relation to an object, you can see and edit the relation direction used in your object description.
-
For an object with more than one identified text option, UFT One performs verification on the text value you select.
-
For cells inside a table, the pop-up dialog box also displays the object hierarchy, row, and column information.
-
You can describe an object by position or relation, but not both.
-
-
Accept or modify the step action, edit the value field, and click Add to test.
Note: When testing non-mobile applications, we recommend selecting SetText to set the value of a text box, rather than the default Type, which sends key inputs to the control.
If you are adding a step when inspecting a live application:
-
After you add a step to your test, click the Run on application button in the right pane to run the step. This verifies that your step is correct, and also advances the application to the next state, re-inspecting the application for the next step.
You can instruct UFT One to provide time for the application to load after running the step, before re-inspecting the application. Click the dot-menu icon next to the Run on application button and configure a delay.
-
To inspect the whole browser window, enabling the test to handle browser pop-ups or prompts, do the following:
-
Click the down arrow near Context , and select Set browser scope to full window .
-
Click the browser window and then go back to the AI Object Inspection window.
The AI Object Inspection window starts inspecting the whole browser window.
-
Add a SetBrowserScope step from the Context menu or right pane to set the context.
-
The step added for each object includes any information used to identify it uniquely, such as associated text or the object's relative location on the screen. For details, see Associate text with objects and Identify objects by relative location.
Note: Avoid adding steps with objects that were incorrectly identified. For example, if a button is identified as a text box, or a check mark is identified as a button, such objects may be identified inconsistently and fail in subsequent test runs.
Add steps when spying on objects
When you identify an AI-based object in the Object Spy or Object Identification Center, you can Drag and Drop the identified object into your test. The step is automatically added to your test.
For details, see Spy on objects in your application.
Add steps using AI Object Record
Use AI Object Record to automatically create AI-based test steps in your test editor.
For details, see Record an AI-based test.
Add steps manually in the Editor
Edit your test using the AIUtil object.
Next, use the AIUtil object to identify the control by type, text, or both, and to perform operations on the objects, such as Click, Type, or Search.
For details, see AI-based Testing in the UFT One Object Model Reference for GUI Testing.
Example:
The following example clicks a settings control on a mobile device and then types a user name in the appropriate field. Both controls are identified visually using AI.
Next, the Log In text is located on the screen and clicked.
After logging in, this example clicks an "ON" button. Because the application contains a few similar buttons, the example specifies that button to click is the third button from the top.
AIUtil.SetContext Device("device") 'Set the context for AI AIUtil("settings").Click AIUtil("input", "USER NAME").Type "admin" AIUtil.FindTextBlock("Log In").Click AIUtil("button", "ON", "FromTop", 3).Click
Tip: UFT One generates steps that use FindTextBlock, as the spy identifies full blocks of text. When you create your own steps, consider using the FindText method, which will match the text you provide, even if it is only part of a larger text block.
Add checkpoints to your test (optional)
You can add different types of checkpoints to check the existence of an object or its state. The checkpoint passes if the application is in the expected conditions. Otherwise, a step failure is reported in the run results.
Checkpoint method | Description | Condition |
---|---|---|
AIObject.CheckExists or AITextObject.CheckExists |
Check the existence or absence of an object in your application. |
Specify whether you expect the object to exist or not when this step runs. |
AIObject.CheckState |
Check the state of objects that can be set to Off or On, such as check boxes, toggles, or radio buttons. |
Specify the expected state of the object. |
Add checkpoint steps in one of the following ways:
-
Enter checkpoint steps in your test manually.
-
Add checkpoint steps in an AI Object Record session. For details, see Add a checkpoint during recording.
-
Select Verify as the action and select Exists or Does Not Exist to verify the existence of the object. Use On or Off to verify the object's state when you edit a step in AI Object Inspection window.
You can retrieve properties, such as height, width, value, and hint from the AI objects in your application. Use the GetObjectProperty and GetAllProperties methods to retrieve the values, then check the values to validate your object's location and content. For a list of properties supported for each object type, as well as details about the Get methods, see AI-based Testing in the UFT One Object Model Reference for GUI Testing.
See also: