Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Postman Tutorial Part 24 -Set, Get and Unset Global & Environment Variables in Postman Scripts

Posted on 02/19/2025 By admin

We have seen creating environment and global variables manually. You can refer them here:-

Understand Environment & Variables in Postman

Create, Manage and Use Environment In Postman

Create, Manage and Use Global Variable In Postman

In above ways, manually we need to add variables with value. Sometimes we may need to update or add variables or values at runtime. For example:- You are creating a user and that user should be used for other APIs. We need to extract user details from response and add to environment. This needs to be done at runtime only.

We can add, update, get or remove global and environment variables at runtime using scripts in Postman. We use a global function named “pm.*” of Postman Sandbox environment. We can do it in both Pre-request Script and Tests.

Setting an environment variable:

pm.environment.set("variable_name", "variable_value");

Getting an environment variable:

pm.environment.get(“variable_name”);

Clear or unset an environment variable:

pm.environment.unset("variable_name ");

Example:-

  1. When we do not select any environment, still we can manage environment variables through scripts. But variable will be accessed till the execution is going on. Variable will be removed once execution is over.

2. When we select any environment, operations performed at variables will persist after execution as well.

Create an environment without any variables. (You can have existing variables in environment. I am taking an empty just for example purpose.)

Now run the same above scripts. Only change is that now we have selected “Auth Data” as Environment.

You can see that variable “FirstName” persists even after execution in environment. If we try to set an environment which is already present in Environment, value will be overwritten.

We can check presence of a variable in an Environment using below sandbox API:-

pm.environment.has(“Variable_Name”)

It returns true if present else false.

Set a global variable:

pm.globals.set("variable_name");

Get a global variable:

pm.globals.get("variable_name");

Clear a global variable:

pm.globals.unset("variable_name");

Since global variables are not dependent on selection of environment, operation performed at global variables persist after execution.

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.#ThanksForReading

#HappyApiTesting

Uncategorized

Post navigation

Previous Post: Front End Automation Strategies 1 – Don’t Write Complex XPath/CSS – Ask For Static Locators Instead
Next Post: Java Program 13: Java Program To Find If Given Numbers Are Coprime

Related Posts

2018 – Make Selenium Easy Uncategorized
October 12, 2018 – Make Selenium Easy Uncategorized
Ways of Handling StaleElementReferenceException Without PageFactory Uncategorized
How Much Java Required For Selenium? | Make Selenium Easy Uncategorized
Architecture of Selenium Webdriver Uncategorized
REST Assured Tutorial 68 – Compare Two JSON using Jackson – Java Library Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark