Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • About Us
  • Toggle search form

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

Posted on 05/19/2022 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.

Managing environment variable using scripts:

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.

Managing global variable using scripts:

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: Postman Tutorial Part 44 – Data Driven Testing in Postman Using CSV File – Make Selenium Easy
Next Post: Selenium Topics Archives – Page 3 of 37 – Make Selenium Easy

Related Posts

REST Assured Tutorial 4 – Let’s Write First GET REST Assured Test Uncategorized
June 25, 2019 – Make Selenium Easy Uncategorized
Selenium Interview Question 7 – How to Select Last Five Checkboxes Uncategorized
Postman Tutorial Part 9 – DIfference Between Put and Patch HTTP Methods Uncategorized
FileUpload – Make Selenium Easy Uncategorized
March 2017 – Make Selenium Easy Uncategorized

Recent Posts

  • How to Set Up Selenium WebDriver with Python Step by Step
  • How to Set Up Selenium WebDriver with Java from Scratch
  • What Is Selenium and Why It Is the Most Popular Test Automation Framework
  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing

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