Calling API tests with parameters - Use-case scenario

Relevant for: GUI tests only

When you are testing your application, you may want to create both GUI and API tests for your application to ensure that the user interface and non-GUI (service) layers perform correctly.

In UFT, run the tests together in a single unified test run by calling the API test from a GUI test (or vice versa).

Sometimes, the GUI layer of your application requires data from the API layer to use in performing user tasks. When creating your test, if you insert a call to an API test from a GUI test, UFT 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.

This use-case scenario demonstrates how a GUI test can call an API test and pass a parameter value from the API test back to the calling GUI test. For the purposes of this scenario, you will be using the flight booking application included with the UFT installation.

Application description

In the flight reservation application, you have 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

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

To perform the tests of the application, you must run both the API and GUI tests, but also call the API test from the GUI test.

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, you must 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, you can 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 navigate to 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, you will 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, you must 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 "REST Services" ,DataTable("APITestOutput", dtGlobalSheet)
WpfWindow("HPE MyFlight Sample Applicatio").WpfTabStrip("WpfTabStrip").Select "SEARCH ORDER"
WpfWindow("HPE MyFlight Sample Applicatio").WpfRadioButton("byNumberRadio").Set
WpfWindow("HPE MyFlight Sample Applicatio").WpfEdit("byNumberWatermark").Set Parameter("FlightNumber")
WpfWindow("HPE MyFlight Sample Applicatio").WpfButton("SEARCH").Click
WpfWindow("HPE MyFlight Sample Applicatio").WpfTable("ordersDataGrid").SelectCell "1", "1"
WpfWindow("HPE MyFlight Sample Applicatio").WpfButton("SELECT ORDER").Click0
            

When the test runs, UFT 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