Testing Web Services

If you are new to web services then please first see the
definition with an example.

You can download the HP Service Test 11 trial


Start HP Flights service (this should keep running while we are creating/running this test):

Start > (All) Programs > HP Service Test 11 > Sample Application.

Closing this window will stop the HP Flights service.


We will test a web service:

Create a new solution. Go File (Menu) -> New -> Test (CTRL+SHIFT+N) and type the name as "sample test service" and click create. You will see a canvas with Start-End Flowchart.

On left hand side you will see a Toolbox. Expand Web Services (it shows only a SOAP Request).

First import a web service.

a. On the toolbar, below Menu, from Import Service select Import Service from URL/UDDI, a "Import Service from URL/UDDI" dialog box opens. Enter "http://localhost:24240/HPFlights_SOAP?wsdl" address in the Address textbox and click ok.

b. Once the service is imported, in the Toolbox you will see HPFlights_Service under Web Services.

Drag GetFlights method to Test Flow.

On right hand side (from Property Sheet), expand Input -> GetFlights node and for DepartureCity type Denver and for ArrivalCity type Los Angeles.

Now drag CreateFlightOrder method on Test Flow, just below the GetFlights.

On right hand side (from Property Sheet), expand Input -> CreateFlightOrder -> FlightOrder node and for Class type Business, for CustomerName type Sachin, for DepartureDate choose some future date, for NumberOfTickets type 2.

For entering FlightNumber follow these steps:

[As it has to get the first flight number from the results generated by GetFlights, we have to link output of GetFlights to the input of CreateFlightOrder]

a. On the right hand side of FlightNumber text field, click on Link to a data source icon.
b. Select Link Source dialog opens.
c. Choose Previous step radio button.
d. Select GetFlights node. 

e. In the Output section, right-click the Flight[…] node and choose Add Array Element from the menu.
f. Expand the Flight[1] array, select the FlightNumber element and click Add. 

g. Click ok to come out of Link Source dialog.

Now your canvas indicates that output of GetFlights method goes as input to CreateFlightOrder method.

Click inside the Test Flow pane (clicking brings green border to it), in the property sheet on the right hand side, select For Loop and enter 1 in the Number of Iterations.

Save the test and run it.

It is fetching all the flights with GetFlights operation and using the first flight from there as an input to CreateFlightOrder operation. To be sure on this let’s see the results:

SOAP message of GetFlights:

SOAP message request: (requests for all flights from Denver to Los Angeles)

SOAP message response: (receives all flights from Denver to Los angeles)
SOAP messages of CreateFlightOrder:

SOAP message request: (as we wanted to take the first flight from the results and we also wanted 2 tickets, so a request is sent for the same)

SOAP message response: (calculated price for 2 tickets we wanted to book)

Let’s include one checkpoint as well:

In the test results window that opens up, on the LHS just expand all nodes and click on the CreateFlightOrder node and on the RHS in the HTTP Response snapshot check the total price (as you see in the above screenshot as 232).

Now for setting a Checkpoint, go to the Service Test canvas where your test is open, On the RHS in the Property Sheet under Checkpoints, type in the value of 232 in Expected Value for TotalPrice and check the checkbox.

Run the test again.
Now in the Test Results you will see a green tick also.

Testing GUI & Non-GUI Applications with QTP

Before reading further make sure you know little bit about Service Test 11.0

Let’s try to run the test we created here via QTP 11.0 (NOT Service Test 11.0) and see how you can test your GUI and UI-Less Application Functionality in One Test.

Open new test in QTP.

Go to Insert (Menu) -> Call to Service Test Test….
Call to Service Test Test window opens.
Navigate to the test (which was created in Service Test 11.0 and saved on the disk).
Select it and click open.
Click OK to come out of Call to Service Test Test window.

It will add a call to Service test as shown below:

var_CallServiceTest = CallServiceTest ("ServiceTest1.st","ServiceTest1Params-2.xml")

This is just a simple example. You can add other code before or after this call to service test in order to see the testing of GUI and Non-GUI part in one test.

Run this test. (Obviously the service should be running, Start-> All Programs->HP Service Test 11.0 ->Sample Application)

It will run the test and show the combined results in the Run Results Viewer.