Create and run a Web service API test

This lesson describes how to create an run a Web service API test, using custom activities imported into UFT from a Web Service Description Language (WSDL) file.

WSDL files can store service descriptions, defining the service metadata and operations or methods. UFT can read the WSDL and create the service's methods and activities for you in the Toolbox pane.

Use custom imported services whenever standard activities do not match the processes that your app performs.

Create a Web service test

Add a Web service test to your MyFlight Application solution to test the Web (API) later of the MyFlights app.

Do the following:

  1. Start with UFT and the MyFlight Application solution open.

    For more details, see Plan your test and create a solution.

  2. Select the Add dropdown in the toolbar, and then select Add New Test.
  3. In the Add New Test dialog:

    • Select API Test.
    • In the Name field, enter MyFlightWebService.
    • In the Location field, ensure that the test is saved in the C:\%HOMEPATH%\Unified Functional Testing directory.

    Click Add to add the test to your solution.

  4. Continue with Import a Web service.

Back to top

Import a Web service

Import the MyFlight service description and its methods into UFT.

Do the following:

  1. Start the Flight API app. For details, see Flights API layer.

    Note: Keep the Micro Focus Service APIs dialog open while performing this lesson to ensure that the Flights API service is running while UFT runs the test.

  2. In the Micro Focus Service APIs dialog, click Copy WSDL Path to copy the service path to the clipboard.
  3. In UFT, select the Import WSDL toolbar dropdown, and select Import WSDL from URL or UDDI.

  4. In the Import WSDL from URL or UDDI dialog, select URL.

    Then click in the Address field and paste the URL to the service path you'd copied from the Micro Focus Service APIs dialog.

  5. Click OK to import the service into UFT.

    The methods are now displayed in the Toolbox pane.

  6. Continue with Build and parameterize your Web service test.

Back to top

Build and parameterize your Web service test

This exercise describes how to build and parameterize a Web service test for the Flights API, including steps to get flights, and create a flight order.

An API service test flow should match the steps in the application flow as closely as possible. You should already be familiar with the steps in the app from the test you created for the GUI layer. For more details, see Create and run GUI tests.

Create your test structure

Do the following:

  1. In the Toolbox pane, expand the Local Activities > Web Services > HPFlights_Service > FlightsServiceMethods to display all the methods imported from the WSDL file.

  2. Drag the GetFlights method to the Test Flow box on the canvas to create the first step.

  3. Drag the CreateFlightOrder method to the Test Flow box to create the second step.

  4. Continue with Link the FlightNumber value to the GetFlights output.

Link the FlightNumber value to the GetFlights output

Do the following:

  1. Select the CreateFlightOrder step in the canvas to display the Properties pane.

  2. In the Input/Checkponts tab on the Properties pane, navigate down to the Body > CreateFlightOrder > FlightOrder > FlightNumber row.

  3. Select or hover over the FlightNumber row, and click the Link to a data source button .
  4. In the Select Link Source dialog, select Available steps at the top.

    On the left, select the GetFlights step.

    On the right, in the Output section, expand the GetFlightsResult node.

  5. In the Flight (array) row displayed, click Add .

  6. Expand the Flight[1] array that's shown, to display a list of all the GetFlights step output properties.

    Scroll down to view the FlightNumber property.

  7. Select the FlightNumber property, and click OK.

    When prompted if you want to enclose the target step in a loop, select No.

    UFT updates the Value column for the FlightNumber property to reflect the link.

  8. Continue with Add a data source to use in your test.

Add a data source to use in your test

Do the following:

  1. Display the Data pane if it's not already shown (View > Data).
  2. In the Data pane, click New Data source , and select Excel.

  3. In the New Data Source dialog:

    • In the Name field, enter WS_Flights.
    • Browse to and select the Excel file stored in the <UFT installation directory>\samples\Flights Application directory.
    • Select Link to the Excel file in its original location.

    Click OK to add the Excel data to your test.

  4. Continue with Link the test step to the data source.

Link the test step to the data source

Do the following:

  1. In the canvas, select the GetFlights step to display the Properties pane.

  2. In the Input/Checkpoints tab of the Properties pane, expand the GetFlights node.

  3. Hover over or select the DepartureCity row, and then click the Link to a data source button .

  4. In the Select Link Source dialog, do the following:

    1. At the top, select Data source column.
    2. On the left, select WS_Flights!Input.
    3. On the right, select DepartureCity.

  5. Click OK to link the DepartureCity property value to the DepartureCity column in the data table.

    UFT reflects this change in the Properties pane.

  6. Repeat the previous steps for the ArrivalCity and FlightDate values.

    For the FlightDate value, select DepartureDate.

  7. Back in the canvas, select the CreateFlightOrder step.

    Repeat these steps again for the following values:

    • Class
    • CustomerName. For this value, first click the blue box to remove the NIL value before linking this property.
    • DepartureDate
    • NumberofTickets

    When you're done, the Properties pane should look like this:

  8. Continue with Set data source navigation settings.

Set data source navigation settings

Configure how UFT handles your data during a test run. Do the following:

  1. In the canvas, select the Test Flow box to display the Properties pane for the test flow.

  2. In the Properties pane, select the Data Sources tab .

  3. Select the WS_Flights!Input entry in the table and click Edit.

  4. In the Data Navigation dialog, specify the data navigation details as follows:

    Start at: First row
    Move by: 3 rows Forward
    End at: Last row
    Upon reaching the last row: Wrap around
  5. Click OK, and save your test.

  6. Continue with Run the Web service test.

Back to top

Run the Web service test

Run the Web service test you created in the previous steps.

Do the following:

  1. Ensure that the Flight API app is still running. For more details, see Plan your test and create a solution.

  2. Define the number of test iterations. In the canvas, select the Test Flow box.

  3. In the Input tab on the Properties pane:

    • Select the 'For' Loop option.
    • In the Number of Iterations field, enter 4.
  4. Click the Run toolbar button .

    Ensure that the MyFlightWebService test is selected, and then click Run to run your test.

  5. When the test is complete and the run results are shown, navigate down in the Test Flow to any of the GetFlights nodes.

    In the captured data for the step, scroll down until the More area is visible. This is where UFT shows the HTTP Request and Response information for the Web service call that was performed.

    For example:

  6. Click the link in the Full Request cell to view the input properties sent for the selected step.

    For example:

  7. Scroll down further and click the link in the OutputXML cell to view the step's output properties.

    For example:

  8. Scroll down further to view the Checkpoint area to display checkpoint results.

    For example:

  9. Continue with one of the other exercises in the tutorial.

Back to top

Next steps: