API Testing Lesson 4
The fourth lesson - we still send PUT,
focusing on the server responses.
From this lesson on I assume that you are already able to create a new Request, change the Path
and know how to run a request.
A new email from the client and our API gets an additional endpoint /api/prod_order/
and a new version of the documentation.
Base URL: 'http://www.answerit.ru' … 4. Resource: /api/prod_order/<int:prod_order_id> Method: PUT Allowed prod_order_id:[10000;20000] Responses: 200 OK application/json {"Success":"PO with id <int:prod_order_id> created."} Order out of allowed range: 412 Precondition Failed application/json {"Error":"This order value is not allowed"} …
I have temporarily removed the requests from the previous lessons, marking their presence with an … sign
Let us look at what is new in this version
Allowed prod_order_id:[10000;20000]
This is a restriction on prod_order_id. In the previous lesson we could pass any integer and
get 200 OK in response.
Now the id has to be from 10000 to 20000.
If we send some wrong number as prod_order_id, the developers have provided a special error 412.
Order out of allowed range:
412 Precondition Failed
An additional error code helps the tester understand what exactly went wrong.
In
the previous lesson
we got error 404 when we entered a string instead of a number (
repeat
)
Check that with /api/prod_order/<int:prod_order_id> it has not gone anywhere either.
Now, having received 404, we understand that something fundamentally wrong was passed.
Having received 412, we know that the request is technically correct, but the passed id does not satisfy
the additional condition.
Let us send a request that, in our opinion, should satisfy the given conditions and
return 200 OK.
For example, let us pass prod_order_id equal to 13243. 13243 is greater than 10000 and less than 20000.
As expected, a 200 OK response came back.
Let us pay attention to the line {"Success": PO with id 13243 created."}
The documentation says the following
application/json
{"Success":"PO with id <int:prod_order_id> created."}
application/json means that the server response is formatted in a special way - as JSON.
The curly braces, quotes and colon come from there.
{"Success":"PO with id <int:prod_order_id> created."} this is an additional hint.
If in this response instead of <int:prod_order_id> there is 13243,
it means the server is responding to our request.
{"Success": PO with id 13243 created."} - everything worked out as we expected.
What happens if we send not 13243 but 7.
7 is less than 10000, so we get error 412. Along with the error a hint will come, also in JSON format
application/json
{"Error":"This order value is not allowed"}
Let us check
Open the same response in the JSON tab
Here only the JSON itself that came from the server is shown.
In the XML tab our response will not be displayed, because it is in a different format
You can look at the HTML tab yourself as an exercise.
Let us check our «old» error 404. We send a deliberately wrong request
/api/prod_order/aredel.com
Still 404 Not Found.
You see Not Found, and you should already know where to check that it is 404 - write in the comments whether it worked or not.
Summary
After the first four lessons you know how to create simple REST requests in
SOAP UI
.
You are familiar with the GET and
PUT
.
You know that on success you should expect a 200 OK response or something similar.
You have seen errors of type 4XX, namely 404 Not Found and 412 Preconditon failed.
You know that the server response can be without a format or in JSON format.
You guess that besides the JSON format there are also, at a minimum, XML and HTML
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