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,
NewDeck - for creating a new deck
Draw - to draw a card/cards from the deck created
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.
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.
${NewDeck#Response#$deck_id}
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
${Draw#Response#$cards[0].code}
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!
댓글