Welcome to exercise four, for day thirty of 30 days of API Testing.
Goal
Loop through a dataset calling an API to create an entity each time using some tools with automated execution capabilities or in code using an API testing framework.
Objectives
- Loop through a dataset calling an API each time
- Gain exposure to many some API testing automation frameworks or tools that support API automation.
Exercise
Choose an API testing automation framework or tool, some suggestions below:
- API Fortress
- Postman
- SoapUI
- RESTAssured (Java)
- SuperTest (JavaScript)
- RESTSharp (C#)
Create a dataset appropriate for that API and loop through it making the API call each time. Many test APIs have been posted for challenge 5. Try treating them as separate tests and adding an assertion after each one. Bonus challenge: add some bad data in there and assert the API rejects it.
Example
Using https://automationintesting.online created by Mark Winteringham and myself, do the following:
- Do a GET call against https://automationintesting.online/room/, you should get 1-N rooms returned. Assert on the correct status code and that the body has a room object.
- Get a token by doing a POST against the auth API at https://automationintesting.online/auth/login endpoint. You’ll need to send the following JSON in order to get a token back.
{
"username": "admin",
"password": "password"
}
- Extract the token and store it
- Do a GET call against https://automationintesting.online/room/, you should get 1-N rooms returned. Extract a room ID from one of the rooms
- Create test data like below, perhaps parameterise the name and date fields
{
"bookingdates": {
"checkin": "2018-11-01T09:48:25.469Z",
"checkout": "2018-11-01T09:48:25.469Z"
},
"depositpaid": true,
"firstname": "<<paramterised data>>",
"lastname": "string",
"roomid": "<<roomid>>",
"totalprice": 0
}
- Loop through all your data doing a POST call against the booking API to make a booking for the room, https://automationintesting.online/booking/.
Share
Post your experiences with the tools you use below.
If you used a different API post the calls you did so others can try them.