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 Inspection or AI 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:

UFT One versions 2022 and later Web Browser, mobile Device, or SAPGUISession.
UFT One versions 2021 R1 and earlier: Web Browser or mobile Device.

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 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 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.

Back to top

Add steps when using AI 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:

  1. Do one of the following: 

  2. Click a highlighted object.

    A pop-up dialog box opens with the suggested step and object description.

    Combo box Select operations

    For details on running Select operations on combo boxes, see Supporting Select operations on combo boxes.

    UFT One version 2022 and earlier: When inspecting live applications, the Select action is available only if UFT One can also identify the combo box as a WebList or a MobileDropDown.

  3. (Optional) Click Edit step to add additional object description properties including Position and Relation in the right pane.

    • 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.

  4. Accept or modify the step action, edit the value field, and click Add to test.

    UFT One 2023 or later: 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:

    1. Click the down arrow near Context , and select Set browser scope to full window .

    2. Click the browser window and then go back to the AI Inspection window.

      The AI Inspection window starts inspecting the whole browser window.

    3. 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.

Back to top

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.

Back to top

Add steps using AI Record

Use AI Record to automatically create AI-based test steps in your test editor.

For details, see Record an AI-based test.

Back to top

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. Since 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.

Back to top

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 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 Inspection window.

UFT One 2023 or later: 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.

Back to top

See also: