Make Selenium Easy

Postman Tutorial Part 33 – Retrieve Path Variables Value in Tests Script in Postman

We have already seen Usage of Path variables in Postman. We may need to retrieve provided path variables for assertion in scripts in Postman. We have already seen about Retrieving query parameters in tests in Postman. In this post we will see retrieving Path variables in tests in Postman.

We can retrive provided path variables only in “Pre-request script” as once request is hit , path variables can not be retrieved as final URI is constructed using path variables. You will get null values if try to retrieve path variables in “Tests” tab. If you want to use path variables values in “Tests” tab, you can store in environment or global variable and use it.

To get value of specific path variable :

To get all path variable in a list:

Let’s create a URI with Path variables :-

Add below code to “Pre-request Scripts” to retrieve path variables:-

Hit the request and check Postman console:-

Import above example collection from here:-

Refer basics of API Testing here.

Refer detailed tutorial of Postman here.

More about API Testing in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

Table of Contents

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Postman Tutorial Part 33 – Retrieve Path Variables Value in Tests Script in Postman

by Amod Mahajan time to read: 1 min
%d bloggers like this: