30 Days of API Testing Day 30: Complete Exercise 4

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

  1. Loop through a dataset calling an API each time
  2. 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:

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:

{
	"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
}

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.

3 Likes

I completed this exercise using data driven feature of Katalon Studio

3 Likes

I used python requests.
Test API was https://jsonplaceholder.typicode.com/posts
Available her https://jsonplaceholder.typicode.com/

Decided to send json data to the API.
Json data:


Sample Python Requests Code

2 Likes

API Fortress have a video that might help some folks navigate this challenge using their tool

2 Likes

I continued using my own framework to complete the last practical one (Exercise 4).
I used a loop to add five rooms more to the system and made bookings to all rooms. I called randomString function to generate firstname and lastname for each booking.

Below is my steps:

  1. Get a token then save to request headers
  2. Add more rooms for booking management system
  3. Get a list of room ids
  4. Make a booking for each room then verify info

5 Likes

Using Katalon, my exercise 4 is:

  1. Create file booking data .xlsx
    image
  2. In Katalon project > Data Files > new Test Data type Excel file
    image
  3. At Profiles > default > Add Global Variables
    image
    4.At Object Repository > New Web service request : BookingRoomDataSet to https://automationintesting.online/booking/ with information get from global variables
    image
    image
    image
  4. At Test Case > New Test Case : exercise4
  • Send request to login to get token (as exercise 3)
  • Setting value to global variables
  • Send request to BookingRoomDataSet
  • Verify results
    image
  1. At Test Suites > New Test Suite : Exercise 4
  • Add test case Exercise 4
    image
  • Click Show Data Binding
  • At Test Data > add data from data file in step 2
  • Setting Variable Binding
    image
  1. Run test suite
    image
3 Likes

I using the Postman for Ex4. I did update the my Exercise 3 to complete this exercise.

Here is my work:

  • Create the bookingdata.csv file for the data
    image

  • Update the body of request to booking to using the data from file instead using the hard-code data.
    image

  • Running the collection with the data file:
    image
    Note: To make sure the data is correct, using the Preview button
    image

  • Here is the result:
    image

P/s: The code on Katalon for this exercise is so cool. I challenge myself do this exercise again on Katalon :smiley_cat:

3 Likes

I completed this exercise with Katalon tool
Here is my work:

  1. Create data data file .csv
    image
  2. Create method GET Room
    image
  3. Create method POST - Get a token
    image
  4. Create method POST to booking room with JSON data
    image
  5. Create method POST to booking room with data driven
  • image
  • image
  1. Create Test Collection execute all test suites
    image
    The Katalon can make it easy :wink:
2 Likes

I used Katalon to complete this exercise as below:

3 Likes

I’ve completed this exercise using Katalon:

TCs-EX4

Testsuite-EX4

2 Likes

For this exercise I also used API Fortress and the Shady Meadows Booking API

This is the dataset I used:

Aline,Birkin,2019-01-21,2019-01-22
Marna,Mattek,2019-10-08,2019-10-10
Del,Varlow,2019-02-10,2019-02-15
Junie,Gerin,2019-11-31,2019-12-16
Ferrel,Parke,2019-02-16,2019-02-18
Ferrel,Parke,2019-02-16,2019-02-18

I loop through the first 5 elements in the array and make bookings based on the values for each record. Each iteration also includes an assertion for a 200 response. The last record is a dupe and since it has a date range that is already booked, the request will fail. I made a separate request and assertion using that specific record

Test Script

Online Report
23%20PM

Shady Meadows UI
12%20PM

1 Like

Made it with RestAssured.

I am basically reading from a json the data and creating the bookings with the data from the json