Create an API test

Relevant for: API testing only

This task describes the workflow and methodology to follow when you create and build a test.

Analyze your application

Before creating a test, you need to analyze your application and determine your testing needs. You need to:

Determine the functionality you want to test. To do this, you consider the various activities that the application performs. What business processes run? What activities are most relevant for the business processes that you want to test?
Identify any processes that run repeatedly.

Plan to create actions in your test for such processes.

As you plan, try to keep the number of steps that you plan to include in each action to a minimum. Creating small, modular actions helps make your tests easier to read, follow, and maintain.

Back to top

Configure UFT according to your testing needs

This can include:

Back to top

Prepare the service references (optional)

Import or build the set of resources to be used by your tests, including:

Note: Skip this step when you will be using only the built-in operations. These activities are available in the Toolbox pane under the Standard Activities section.

Back to top

Build your test structure

Note: API tests cannot be created in a path containing an "equal sign" ('=') character.

To build your basic test structure, do the following:

Create additional test flow steps- optional

Expand the Toolbox pane nodes and drag Flow Control activities onto the canvas:

  • Loop. Enables you to add another loop (the Test Flow loop is always part of a test, and cannot be removed). You specify the loop behavior in the loop's input properties.

  • Condition. Enables you to define conditional branches.

  • Sleep. Indicates a time delay in milliseconds.

Add activities to the test to create test steps

Expand the nodes of the Toolbox pane and drag activities into the Text Flow or a Loop box within the canvas to create test steps. If you added a Condition step, drag activities into the condition branches.

Provide the step properties

Enter the input, output, and checkpoint properties (as needed) for each activity. For details on the input, output, and checkpoint properties available for each activity, see Standard Activities.

If you have a number of activities/steps that are repeated often in your test, consider creating an action and adding the steps to this action. After creating the action, you can call the action each time you need to repeat these steps in your test instead of adding the activities and setting the activity's properties repeatedly.

Back to top

Enhance your test steps

To enhance your test steps, do any of the following:

Define data sources for the test

For details, see Assign data to API test/component steps.

Create a Custom Code activity
  1. Select the Custom Code activity from the Miscellaneous category and drag it into a loop.
  2. Click the Input/Checkpoints tab in the Properties pane.

  3. Click Add Properties and create the required input and output properties.

  4. Open the  Events tab in the Properties pane.

  5. Double-click the Handler column of the ExecuteEvent row. UFT opens a new tab TestUserCode.cs.

  6. Locate the Todo section and enter your custom code. Follow the sample code in the comments and use autocompletion to write your code.

  7. Click File > Save All to save the custom code and the test.

Add an event handler - optional

For any activities, you can define default event handlers for checkpoints, and before and after step executions.

  1. Select a step in the canvas and open the Events tab in the Properties pane.

  2. In the row containing the event execution point you want (before, after,etc.), select Create a default handler.

  3. Edit the code in the TestUserCode.cs tab. Locate the Todo section and add your custom code. Follow the sample code in the comments and use statement completion to create an expression.

  4. To access the properties of an activity, cast it before the activity name. For example, see below.

  5. Click File > Save All to save the TestUserCode.cs file and the test.

    For details and examples, see Event Handlers for API test steps.

Example: casting activity properties before the activity name.

ConcatenateStringsActivity cat = args.Activity as ConcatenateStringsActivity;
args.Checkpoint.Assert.Equals(cat.Prefix+cat.Suffix, cat.Result);

Back to top


After you create your test, you can perform different types of runs to achieve different goals. You can:

Run your test to check your application.

The test starts running from the Start step in the canvas and stops at the end of the test. While running, UFT performs each step in your test, including any checkpoints.

If you parameterized the test using data from a data source stored in the Data pane, UFT repeats the test (or test flow loop, if needed) using the data as defined in the Input tab for the Test Flow or test flow steps.

Run your test to debug it.

Before running a debugging session, make sure to enable debugging capabilities by selecting the Run test in debugging mode option in the General Pane.

For general details on debugging, see Debugging Tests and Components. For details on the available debugging panes, see Debug Panes.

Run an individual step.

Select the step in the canvas and choose Run Step from the context menu to run the step with its property values. Note the results in the Run Step Results pane, in the lower section of the main window. If something needs to be modified, do so at this point.

Back to top