https://www.qatechies.com

Postman: Passing Values Between Tests

Postman: Passing Values Between Tests

Hello, welcome back. So we were discussing about installation, then setting up our initial tests and setting up the environment. We also saw how to pass environment variable value into the test. We also saw an advance example with environment variable too. Now its turn for us to move ahead and learn something more with tests. In this article we will see how to pass values between tests.

Let us understand simple business requirement here:

Business Question: Verify whether “Walder” is the character in the first book?.

Solution:

We need 2 tests-  one test which we will make the call of an Rest API and store the required value in the variable, and later we will use the value of this variable in other test.

Okay, we had setup the scripts already using the open API called “An API Of Ice and Fire: https://anapioficeandfire.com/api/” in our last discussion.

We already have the Get Books request with us. We will now create another variable called “PassFirstCharacterUrl” in this first test, but again question is how to retrieve its value and store here ?.

Pass First Character Url
Pass First Character Url

Now look at the Get Books response, you can see that response is huge and has many arrays. These arrays have many information per book, per character etc. Okay, so our business is asking whether Walder is a character in the first Book and verify it.

Traversing the Response

To traverse till the characters array:


The Characters array’s first element is what we need to get to and extract the character named “walder” details.

So to reach to this point we go like this :


 

Put this code in your first tests , below is the image for your reference as for the final look:

Complete Code for Saving Values From Response
Complete Code for Saving Values From Response

 

Now comes the second tests, where we will utilize the url and verify the details. But wait what are we going to put in our endpoint?

So answer is we need to put the url itself which we are saving in first test. Hence, create another test named “Get First Character And Verify Name” in which we will use the environment variable as

{{PassFirstCharacterUrl}} .

If you hover now on this variable it shows “Unresolved Variable” as this is not created yet. Don’t worry on this , it just to make you aware its normal.

Second Test with Passed Variable In Use
Second Test with Passed Variable In Use

Also Add below code to verify the name existence in your Tests tab:


 

Running the Tests

Okay, so lets start our first case, click Send and notice it should save some value against the variable in the Environment Section.

Environment Variables Response Value Saved in a Variable
Environment Variables Response Value Saved in a Variable

 

Now run the other test and go to Test Results:

Verification that Walder Text is present
Verification that Walder Text is present

 

Note: I hope you are with me till the end. In case you face some issue just post your query.

This concludes our discussion on how to get value from responses and storing it in the variables plus passing it between the tests. Now lets explore more advanced case where we need to verify within same Characters array multiple indexes with different set of information to verify within it. Sounds interesting, right !. Lets connect in our next article.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

advanced-floating-content-close-btn 
*************************** Do you want to learn TOSCA? Do you want to excel in Career? Try my New Courses: 1. Tricentis Tosca and Working with Excel   2. Tricentis Tosca and UI Automation Great News!!   Price has been slashed down for limited period of time.So Hurry!!! Click The Shown Links and Enjoy Learning. ***************************
 
error: Content is protected !!