Postman: Passing Values Between Tests
August 28, 2025
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 ?.

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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[ { "url": "https://anapioficeandfire.com/api/books/1", "name": "A Game of Thrones", "isbn": "978-0553103540", "authors": [ "George R. R. Martin" ], "numberOfPages": 694, "publisher": "Bantam Books", "country": "United States", "mediaType": "Hardcover", "released": "1996-08-01T00:00:00", "characters": [ "https://anapioficeandfire.com/api/characters/2", "https://anapioficeandfire.com/api/characters/12", "https://anapioficeandfire.com/api/characters/13", "https://anapioficeandfire.com/api/characters/16" ...} "povCharacters": [ "https://anapioficeandfire.com/api/characters/148", "https://anapioficeandfire.com/api/characters/208", "https://anapioficeandfire.com/api/characters/1109", ... "https://anapioficeandfire.com/api/characters/1303" ] }, |
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 :
|
1 2 |
let responseData = pm.response.json(); pm.environment.set("PassFirstCharacterUrl", responseData[0].characters[0]); |
Put this code in your first tests , below is the image for your reference as for the final look:

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.

Also Add below code to verify the name existence in your Tests tab:
|
1 2 3 4 |
let responseData = pm.response.json(); pm.test("Body matches string", function () { pm.expect(responseData.name).to.eq("Walder"); }); |
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.

Now run the other test and go to Test Results:

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.

