Saturday 16 August 2014

Testing of Java Web Service Client using QTP


Introduction:

This document deals with the steps to be followed for automating the testing process of a front end application using Mercury’s – Quick Test Professional (QTP). All of us know how much useful Automation can be when compared to Manual testing especially when it comes to regression testing. This document will come in handy for people trying to automate their applications (if it is a java based application, even better!) using QTP.

About our application:

Our project is a multi channel integration project and uses different technologieslike Java, .Net etc.
The project is basically an Item search application, used by the store keepers to view the Item related information. The front end is done using .NET and the business is implemented using java web services. The .NET application calls the web services which in turn hit the database to fetch the Item information.
A jsp client has been generated for each web service using which we can test the web service. Our web services will take multiple inputs, of which some values are mandatory. Also the inputs can be given in different ways. We will explain a simple web service which covers all the scenarios. First, we will tell what the web service will do.
Fig 1.0 shows how the web service client Jsp. Once we click on a particular method on left pane we will get a window which is shown in Fig 1.1.


                                                             Fig 1.0
                                                            Fig 1.1

Once we give the input values (Either Barcode or dpci or catalog Number or asin) and click on ‘Invoke’ button we will get the result in the Result frame as shown in Fig 1.2. The timestamp is a mandatory field which needs to be given.   
                                                            Fig 1.2

The output appears at the bottom of the frame and is in the form of a Web table as shown in Fig 1.2.


The Role of QTP          

In order to automate the testing of the web application we used QTP 9.0, we have used standard check points to validate the outputs.

We are not querying the database directly due to certain restrictions. We are following a simpler method as an alternative.

We have our inputs and the expected results in two separate work sheets of the same excel workbook .We will load both the work sheets at the very beginning of our script.








Below are the processes and steps to be followed while testing your application with QTP:

Record:

  1. For recording first time initially on , Click on the Record button (highlighted in the tool bar ) and record the application to be tested by giving the url for the web service in the placeholder as shown in Fig 2.0


                                                             Fig 2.0













  1. The application will open up and now give the required input values. The result as we have said earlier appears in the bottom frame.

  1. All the actions, performed by us on the application will be recorded automatically and can be seen both in the Keyword View and the Expert View.


  1. To make sure all the fields you have entered are captured, go to the Resources Menu option in the Menu bar, and select Object Repository. We will get a window as seen in Fig 2.1. Here we notice that all the required fields in the application are captured as objects and can be either of type “text”, “table” etc.

                                                             Fig 2.1







CheckPoint

1. As we need to validate the output results, insert a standard check point to it. To insert a standard checkpoint, go to Insert ->Checkpoint -> Standard Checkpoint as shown in Fig 2.2.



                             Fig 2.2















 2.  Once we identify where in our application we want to place the checkpoint (ie. Which fields we want to validate in our results), we go ahead and place the checkpoint accordingly.

    3.  In our case, the field that we want to insert the checkpoint for is in the form of a Web Table, placing a checkpoint on it would look like as shown in Fig 2.3
                                                      Fig 2.3













  1. Once we click on “OK” button, we will get a screen (Fig 2.4) which shows check point properties which can be modified as per our requirement.


                                                            Fig 2.4




















  1. The above screen shows that QTP has captured a lot of fields which need not be validated. We can uncheck some of the field properties as shown in Fig 2.5 so that QTP will only validate the ones which are checked.


                                                                Fig 2.5


What we need in our testing is to check for the barcode value, deptDesc value, etc. This step is vital because what ever the fields we check here will only be validated while comparing the actual result with the expected result.

Till now we have completed recording for a single input and putting a check point for the output we have obtained. Now we will do parameterization for both inputs and outputs. The script will run for multiple inputs taking data from the excel sheet.
QTP can load only a single excel in the script. However point to note is that it allows loading multiple sheets of the same excel.



Parameterization:

  1. First, import the external excel work sheet containing the inputs into the Global data sheet before starting the testing process.
  2. In the Table Checkpoint Properties, across each field one can find the constant value. Select the radio button: Parameter. Click on the button at the right extreme of the placeholder of the Parameter option. Fig 2.6

                         Fig 2.6

  1. Select the radio button: Global Datasheet and select the column name as it appears in the Global datatable imported at the beginning of the test. 
  2. Repeat the same for all the fields in the Table which need to be validated.
  3. We can use the “Current action sheet” option if we are importing another sheet into our script. Once we select the option, everything will be similar to that of global datasheet option.
We have used this option as we placed our inputs in one work sheet and expected outputs in other work sheet (of the same excel).







The process of placing a checkpoint will be captured in the QTP script in the Expert View, as highlighted below in Fig 2.7.


                                                                Fig 2.7


Note:

Also as we can see from the above figure, we have 2 rows of data in the data sheet, therefore we place the statement: DataTable.SetNextRow.

This is necessary as if this is in place, QTP would now go and read the data from the next now of the DataTable.

Thus now we have a simple but effective script ready to test our application.







Run and Validate the Result:

1.      Select the Run option from the Tool bar. This would lead to opening your application which is to be tested. QTP would then insert the input values in the application, taking it from the data sheet and would compare the actual outcome with the expected (again from the datasheet).

2.      To Check the outcome of your test ,select the Results option from the Automation menu option , See Fig 2.8



Fig 2.8







3.      On selecting the Results option, we get a screen as in Fig 2.9. , where we the outcome of the test is displayed clearly. Here we see that we have 2 “Failed” cases, ie. After running the test script for both the rows of input, the output which is got is not in sync with the Actual Result.
4.      The details of this non synchronization can be seen in the “Tree view” which is seen in the left hand side of the screen .As one can see Red Crosses appear wherever the test case has failed. One can go to the result element in the tree and find out exactly where and what the mismatch is.



                                                               Fig 2.9


5.      If the outcome of the test is positive, one can notice green colored tick marks in   the left hand side tree view.









Conclusion:

Thus we have seen how to generate a QTP script for a simple scenario and verify the test results. The standard checkpoint has been effectively used in our script where the output comes in a table format. We can exactly check the fields in the output. May be there are other options available, but the method we described here is the simplest and yet equally effective.


0 comments :

Post a Comment