Automating Rest API

Updated: Jan 3, 2021

If you didn't learn how to work with styles and parameters of Rest request please refer working with rest project.

As we already know how to create test case from requests, Let's dive in to automating it.

As per our previous example, we have created our scenarios to test "deck of cards" public API, let's create test steps for each scenario in a new test case.

Now we have created three test steps for each scenario,

  1. NewDeck - for creating a new deck

  2. Draw - to draw a card/cards from the deck created

  3. Discard - used to discard the card drawn/created.

While working around as scenarios in working with rest project, we have passed the deck_id manually as a query parameter. Let's see how to pass that via code.

  1. NewDeck test request run and create a new deck of cards.

2. In draw test request, we can draw the cards by passing the deck_id created in previous test request "NewDeck". To pass the value, we are calling the value from response and passing it through the request.

So let's enter the following property expansion under value tab to call the value of deck_id from the response of New Deck.


and if we see the response, deck_id created in "NewDeck" test step is been reflected. And a card is been drawn.

3. In discard test step, we are again passing the deck_id in the same way before. Here one more parameter "cards" are passed at the end of the URL. So, to pass the card value, we are taking the first card drawn from the "draw" test request.

if you observe the response of draw request, cards are created as,

cards:[ {
"code" : "AS"

so the code is present inside cards. we are using the property expansion under value tab as


to pass the card created first in the response of draw test step.

and hence the card is discarded. When we execute the whole test case, the test case is passed.

Happy Testing!

26 views0 comments

Recent Posts

See All

A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of characters you need to delete to make s good. The f

The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.