API Testing Lesson 8
PUT with parameters
Let us sum up the first seven lessons briefly.
We have API documentation for five different endpoints of the
answerit.ru site
I suggest opening it in a separate tab, click
here
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:
The /api/multiply_two/ address has gained 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.
In the
third lesson
You already passed a number with PUT, right 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 /api/multiply_two/ address with New Method Now our project looks as follows, in its own original way:
Select the Request we have just created with the PUT method
Click on the Parameters box at the top right.
A separate window for entering parameters should appear.
You need to click on the green plus.
Two fields for entering parameters and their values should appear.
In the Name field enter factor_1 and 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
Note 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 you could perhaps simply append these values to the URL, not forgetting to put a question mark.
Close the window with the parameters if you have not done it yet and send the request.
We have checked that a 200 OK response arrived with a body in JSON format
{"Success": "Product of 7.5 and 3.3 is 24.75"}
Now let us test it for handling wrong input.
The specification said that the developer has provided for this and returns error
412.
(
view the specification
)
Click on Parameters again and edit factor_1.
Let it now be a set of letters.
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"}
Now let us do the opposite: make the value of factor_1 a number again and make the value of factor_2 a set of letters, and send the request.
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 on the bug you found and post it in the comments.
A big request - do not send too many requests. I am not sure what load the site will bear on my plan.
Article author: Andrei Olegovich