Call API tests with parameters - Use-case scenario

Relevant for: GUI tests only

This use-case scenario demonstrates how a GUI test calls an API test and passes a parameter value. For the purposes of this scenario, you will use the flight booking application included with the UFT One installation.

Application description

In the flight reservation application, there are five main user areas:

  • A login area

  • A flight finder window, where users enter their flight preferences

  • A flight selection window, where users select the best flight for their flight preferences

  • A flight booking window

  • A flight order search

The application has an API that retrieves a flight order, including details about the airline, departure and arrival cities for the flight, departure and arrival times for the flight, flight number, and the price of the flight. You use this information in the user interface of the application to retrieve flight orders saved in the database.

Back to top

Test description

In this scenario, you create both GUI and API tests for your application to ensure that the user interface and non-GUI (service) layers perform correctly. Run the tests together in a single unified test run by calling the API test from a GUI test (or vice versa).

The GUI layer of your application requires data from the API layer for user tasks. When creating your test, for each call to an API test, UFT One enables you to pass the parameter from the API and then helps you select the right place to store this value until the GUI uses the parameter's value.

You want to test multiple things:

  • The API retrieves the flight information

  • The GUI performs searches in the flight database correctly

  • The GUI can take a value retrieved by the API and use it to search the flight database

Back to top

Step 1: Create a test output parameter for the flight data

Since the flight number data (retrieved from the API) is contained in the response of the Get step, the GUI test has no ability to access individual step outputs.

To retrieve this value, you must create a test output parameter in the API test that enables you to pass the API test step output to the GUI test.

In the API test, click on the End step.

In the Test Input/Output Parameters tab of the Properties pane, create a new output parameter, called FlightNumber.

The test output parameter type must be Float.

Back to top

Step 2: Link the test output parameter to the Get step output

After you create the parameter, link the test output parameter to the Get step output.

Click the Link to data source button in the Test Input/Output Parameters tab, and then select the Get steps from the Available steps option.

Back to top

Step 3: Call the API test from the GUI test

Now that you have created an output parameter for the API test and linked it to the test step's output, call the API test from the GUI test.

In the GUI test action, insert a call to an API test using the Design > Call to Existing API Test/Action command.

Then you can see the output parameter in the Call to API Test/Action dialog box after you select the API test.

Back to top

Step 4: Select where to store the output parameter data

From the Call to API Test/Action dialog box, select where in the GUI test to store the output parameter data.

In the Value column for the FlightNumber parameter, click the Configure icon and open the Storage Location Options dialog box.

For this use-case scenario, save the output parameter as a GUI test data table parameter in the Global data table:

Shows how you store the API test output parameter as a GUI test data table parameter.

Back to top

Step 5: Link an action parameter to the data table

  1. In order for the steps in the action to access this value, however, create an action parameter in the GUI test and link this action parameter to the data table.

    In the Parameters tab of the Properties pane, add an input parameter for the action called FlightNumber of type Number.

  2. Link the value of the action parameter to the Data Table parameter.

    In the canvas, right-click the action name and select Action Call Properties.

    In the Action Call Properties dialog box, in the Parameter Values tab, click the Configure icon again and link to the Data table parameter:

Back to top

Step 6: Parameterize the GUI test steps

Once the action parameter is linked to a GUI Data table parameter, you can parameterize the GUI test steps.

In the test steps, parameterize the byNumberWatermark.Set step with this data table parameter:

Back to top

Final test step descriptions

Your test steps now look like this:

In the Editor, the steps are displayed like this:

RunAPITest "MyFlightWebService" ,DataTable("APITestOutput", dtGlobalSheet)
WpfWindow("Micro Focus MyFlight Sample").WpfTabStrip("WpfTabStrip").Select "SEARCH ORDER"
WpfWindow("Micro Focus MyFlight Sample").WpfRadioButton("byNumberRadio").Set
WpfWindow("Micro Focus MyFlight Sample").WpfEdit("byNumberWatermark").Set Parameter("FlightNumber")
WpfWindow("Micro Focus MyFlight Sample").WpfButton("SEARCH").Click
WpfWindow("Micro Focus MyFlight Sample").WpfTable("ordersDataGrid").SelectCell "1", "1"
WpfWindow("Micro Focus MyFlight Sample").WpfButton("SELECT ORDER").Click

When the test runs, UFT One stores the output parameter value from the API test in the Data table, and this parameter is then used in the GUI test step:

Back to top