API Testing Lesson 7

PUT with parameters

We continue to complicate working with /api/multiply_two/ so that in the future we are not afraid of «complex» constructs.

Now you can multiply not only with POST but also via PUT:

Base URL: 'http://www.answerit.ru' … 5. Resource: /api/multiply_two/ Method: GET Response: 200 OK This endpoint allows to multiply numbers. Use POST method to send two numbers factor_1 and factor_2 of type int or float. format request body as JSON. Response will include info about their product. Method: PUT Parameters: factor_1,factor_2 : float Responses: 200 OK application/json { "Success":"Product of %factor_1% and %factor_2% is %product%" } where %product% = %factor_1% * %factor_2% 412 Precondition Failed if factor_% is not integer or float application/json { "Error 412":"factor_% is not a number" } Method: POST Body: { "factor_1" : float, "factor_2" : float } Responses: 200 OK application/json { "Success":"Product of %factor_1% and %factor_2% is %product%" } where %product% = %factor_1% * %factor_2% …

What is new in the documentation:

/api/multiply_two/ now has a third supported method

In the previous lesson you could send GET to get reference information and POST with a body in JSON format to multiply

In the current version you can also send PUT, and with two parameters at that.

In the third lesson You already passed a number with PUT, directly in the URL. In SOAP UI this means that you entered it in the Resource field.

Now you can learn a new way of passing data.

As usual, you need to add another method to the address /api/multiply_two/ using New Method Now our project looks quite original:

API testing example image from website www.aredel.com

Select the Request we have just created with the PUT method

Click in the Parameters box at the top right.

API testing example image from website www.aredel.com

A separate window for entering parameters should appear.

You need to click the green plus.

API testing example image from website www.aredel.com

Two fields for entering parameters and their values should appear.

API testing example image from website www.aredel.com

In the Name field enter factor_1 in the Value field enter 7.5

Click plus again and enter factor_2 with the value 3.3

Press Enter or simply close this window

API testing example image from website www.aredel.com

Pay attention to the Parameters field. An entry has now appeared there

?factor_1=7.5&factor_2=3.3

This is exactly how the request will be sent. If you were now using some other tool and not SOAP UI then you could probably just append these values to the URL, not forgetting to put a question mark.

Close the window with the parameters, if you have not done so yet, and send the request.

API testing example image from website www.aredel.com

We have checked that a 200 OK response came back with a body in JSON format

{"Success": "Product of 7.5 and 3.3 is 24.75"}

Now let us test the handling of incorrect input.

The specification said that the developer has provided for this and returns an error 412.
( view the specification )

We click Parameters again and edit factor_1.

Let it now be a set of letters.

API testing example image from website www.aredel.com

We send the request and see that the handling was successful. The server understood that we sent not a number and returned 412 with a warning in JSON format.

{"Error 412": "factor_1 is not a number"}

API testing example image from website www.aredel.com

Now let us do the opposite: make the value of factor_1 a number again and the value of factor_2 a set of letters, and send the request.

API testing example image from website www.aredel.com

And here we see an obvious bug.

HTTP/1.1 500 INTERNAL SERVER ERROR Server: nginx-reuseport/1.13.4 Date: Fri, 05 Jun 2020 09:57:59 GMT Content-Type: text/html; charset=utf-8 Content-Length: 290 Connection: keep-alive Keep-Alive: timeout=30 X-Powered-By: Phusion Passenger 4.0.60 Status: 500 INTERNAL SERVER ERROR <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>500 Internal Server Error</title> <h1>Internal Server Error</h1> <p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

The developer checked factor_1 but forgot to do the same with factor_2

As an exercise, write a letter to the developer with a report about the bug you found and post it in the comments.

Summary

In this lesson you have seen that three methods can be attached to one address at once.

The main value of the lesson is working with parameters. Now you know that after the ? in a link there is not something secret, but quite specific data, which you can now create yourself in SOAP UI in the future you will master other ways too, for example with Python , but for now the main thing is to understand that it is possible and to be able to use at least one tool.

In the next lesson we will analyze the API specification, which has grown quite extensively, and try to make improvements based on the existing knowledge.

Remember that your feedback helps me choose the right direction. Write in the comments if something worked out or did not work out.

A big request - do not send too many requests. I am not sure what load the site on my plan can withstand.

Article author: Andrei Olegovich