Create and run a WADL service API test

This lesson describes how to create and run a Web Application service API test, using custom activities imported into UFT One from a Web Application Description Language (WADL) file.

WADL files can store service descriptions, defining the service metadata and operations or methods. UFT One can read the WADL 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 test for a Web Application service test

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

Create the API test:

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

    For more details, see Start UFT One and create a solution.

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

    • Select API Test.
    • In the Name field, enter MyFlightWADL.
    • In the Location field, ensure that the test is saved in the C:%HOMEPATH%\My Documents\UFT One directory.

    Click Create to add the test to your solution.

  4. Continue with Import the MyFlight Web Application service model.

Back to top

Import the MyFlight Web Application service model

Import the MyFlight WADL service description and its methods into UFT One.

Import the WADL service description and methods:

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

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

  2. In the OpenText Flights Service APIs dialog, click Copy WADL Path to copy the service path to the clipboard.
  3. In UFT One, select the Add REST Service toolbar drop-down, and select Import WADL from URL.

  4. In the Import WADL from URL dialog, paste the URL to the WADL path you'd copied from the OpenText Flights Service APIs dialog.

  5. Click OK to import the service into UFT One.

    The methods are now displayed in the Toolbox pane.

  6. Continue with Edit the Web Application service methods in your test.

Back to top

Edit the Web Application service methods in your test

This exercise describes how to add additional properties to the service description imported from the WADL file, which will be used as the prototypes whenever you add a method to your test.

The original data imported from the WADL file is read-only, and cannot be modified after being imported.

Edit the web application service methods:

  1. Copy the following lines of code to a text editor, and save the file as response.xml.

    <ArrayOfFlight xmlns="HP.SOAQ.SampleApp" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
     <Flight>
       <Airlines>AA</Airlines>
       <ArrivalCity>Denver</ArrivalCity> 
       <ArrivalTime>01:23 PM</ArrivalTime> 
       <DepartureCity>London</DepartureCity> 
       <DepartureTime>06:12 AM</DepartureTime> 
       <FlightNumber>20279</FlightNumber> 
       <Price>112.2</Price>
     </Flight>
    </ArrayOfFlight>
    
  2. In the Toolbox pane, right-click the Flight Service node, and select Edit Service.

  3. In the Edit REST Service dialog, select the Flight Service > Flights_REST > Flights > GetFlights node on the left.

  4. Select the HTTP  tab on the right, and define the Response Body as XML.

  5. In the Response Body section, click , and browse to and select the response.xml file you created in step 1.

    The imported properties are shown in a grid.

  6. Click to show the properties you copied in a grid view. These are some of the properties you'll use in this test.

  7. In the Edit REST Service dialog, select the Flight Service > Flights_REST > FlightOrders > ReserveOrder node.

  8. Select the HTTP  tab on the right, and define the Request Body as XML.

  9. With the view selected, copy the following code into the XML edit box:

    <?xml version="1.0" encoding="utf-8"?>
    <FlightOrderDetails xmlns="HP.SOAQ.SampleApp">
     <Class>Business</Class>
     <CustomerName>John Doe</CustomerName>
     <DepartureDate>2019-12-12</DepartureDate>
     <FlightNumber>1304</FlightNumber>
     <NumberOfTickets>21</NumberOfTickets>
    </FlightOrderDetails>
  10. Click to show the properties you copied in a grid view. These are the rest of the properties you'll use in this test.

  11. Click OK, and save your test to save the changes to the service model you imported from the WADL file.
  12. Continue with Build a MyFlight Web Application service test.

Back to top

Build a MyFlight Web Application service test

This exercise describes how to build a Web Application service test using the MyFlight service methods you imported and modified in your test. When you're done, your test will include 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 your test structure.

This section includes the following parts: 

Create your test structure

  1. In the Toolbox pane, expand the Local Activities > REST Services > Flight Server > Flights_REST > Flights node.

  2. Drag the GetFlights method to the canvas to create the first step.

  3. In the Toolbox pane, expand the FlightOrders node, and drag a ReserveOrder method to the canvas to add the second step.

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

Link the FlightNumber value to the GetFlights output

  1. In the canvas, select the ReserveOrder step to display the Properties pane on the right.
  2. In the Properties pane, select the HTTP tab .

  3. Hover over or click in the FlightNumber Value cell, and click the Link to a data source button .

  4. In the Select Link Source for 'FlightNumber' dialog:

    • At the top, select Available steps.
    • On the left, select the GetFlights step.
    • On the right, select the FlightNumber property.

  5. Click OK for UFT One to update the FlightNumber value as parameterized from the GetFlights step output.

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

Add a data source to use in your test

  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 WADL_Flights.
    • Browse to and select the Excel file stored in the <UFT_One_installdir>\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 steps to the data sources.

Link the test steps to the data sources

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

  2. In the Input/Checkpoints tab of the Properties pane, hover over or click the DepartureCity Value cell, and click the Link to data source button .

  3. In the Select Link Source dialog:

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

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

  5. Repeat the previous steps for the ArrivalCity and Date values.

    For the Date value, select DepartureDate.

  6. Back in the canvas select the ReserveOrder step to display the Properties pane on the right.

  7. In the HTTP tab , repeat these steps again to parameterize the following values:

    • Class
    • CustomerName
    • DepartureDate
    • NumberofTickets

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

  8. Save your test, and continue with Set data source navigation settings.

Set data source navigation settings

Configure how UFT One handles your data during a test run:

  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 WADL_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 MyFlight WADL service test.

Back to top

Run the MyFlight WADL service test

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

Run the WADL service test:

  1. Ensure that the Flight API app is still running. For more details, see Analyze your application.

  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 8.
  4. Click the Run toolbar button .

    Ensure that the MyFlightWADL 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 the ReserveOrder node. The run results display a summary of the step.

  6. In the captured data, note the Request and Response information.

    Click on the links in the Request Body and Response Body cells to open the XML response and request information in a browser window.

    RequestBody

    <FlightOrderDetails xmlns="HP.SOAQ.SampleApp">
    	<Class>Economy</Class>
    	<CustomerName>Clark Frank</CustomerName>
    	<DepartureDate>2115-06-01</DepartureDate>
    	<FlightNumber>1089</FlightNumber>
    	<NumberOfTickets>3</NumberOfTickets>
    </FlightOrderDetails>
    

    ResponseBody

    <CreatedOrderParams xmlns="HP.SOAQ.SampleApp" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    	<OrderNumber>87</OrderNumber>
    	<TotalPrice>1767.6</TotalPrice>
    </CreatedOrderParams>
    
  7. Continue with one of the other exercises in the tutorial.

Back to top

Next steps: