Postman Beginner Tutorial 8 | Get and Set Variables with Scripts

  Рет қаралды 51,364

Automation Step by Step

Automation Step by Step

2 жыл бұрын

All FREE courses - automationstepbystep.com/
After watching take this QUIZ - forms.gle/H4fpbJBBe5asqK5K9
How to get variables through scripts
How to set variables through scripts
Set Variables with script
Global: pm.globals.set("name", "Edison");
Collection: pm.collectionVariables.set("name", "Newton");
Environment:pm.environment.set("name", "Rutherford");
Local: pm.variables.set("name", "Ramanujan");
Get Variables with script
Global: pm.globals.get("name");
Collection: pm.collectionVariables.get("name");
Environment: pm.environment.get("name");
Local: pm.variables.get("name"); **access a variable at any scope including local based on priority
*Priority*
Local
Data
Env
Collection
Global
To remove: pm.environment.unset("name");
To print variable value: console.log(pm.variables.get("name"));
____________________________________________________________
Stories by Raghav - automationstepbystep.com/stor...
My Udemy Courses - automationstepbystep.com/udem...
#PostmanScripts
Every LIKE & SUBSCRIPTION gives me great motivation to keep working for you
You can support my mission for education by sharing this knowledge and helping as many people as you can
If my work has helped you, consider helping any animal near you, in any way you can.
_______ ONLINE COURSES TO LEARN _______
automationstepbystep.com/free...
GitHub - github.com/Raghav-Pal/
Udemy - www.udemy.com/user/raghav-pal-3/
Training by Raghav at your venue - raghav.qna@gmail.com
Training schedule - automationstepbystep.com/trai...
----------- UI TESTING -----------
Selenium Beginners - bit.ly/2MGRS8K
Selenium Java Framework from Scratch - bit.ly/2N9xvR6
Selenium Python - bit.ly/2oyMp5x
Selenium Tips - bit.ly/2owxc50
Selenium Builder - bit.ly/2MKNtlq
Katalon Studio - bit.ly/2wARFdi
Robot Framework with RIDE- bit.ly/2Px6Ue9
Robot Framework with Eclipse - bit.ly/2N8DZxb
Protractor - bit.ly/2KtqVkU
TestProject - bit.ly/2DRNJYE
----------- API TESTING -----------
Web Services (API) - bit.ly/2MGafL7
SoapUI - bit.ly/2MGahmd
Postman - bit.ly/2wz8LrW
General - bit.ly/2PYdwmV
Katalon Studio API Testing - bit.ly/2BwuCTN
----------- MOBILE TESTING -----------
Appium - bit.ly/2ZHFSGX
Mobile Playlist - bit.ly/2PxpeUv
----------- CI | CD | DEVOPS -----------
Jenkins Beginner - bit.ly/2MIn8EC
Jenkins Tips & Trick - bit.ly/2LRt6xC
Docker - bit.ly/2MInnzx
Kubernetes - bit.ly/2MJIlMK
------------VIRTUALISATION------------
Virtualization on windows - bit.ly/2SItIL9
----------- VERSION CONTROL SYSTEM -----------
Git & GitHub - bit.ly/2Q1pagY
GitLab - bit.ly/2kQPGyQ
----------- PERFORMANCE TESTING -----------
JMeter Beginner - bit.ly/2oBbtIU
JMeter Intermediate - bit.ly/2oziNVB
JMeter Advanced - bit.ly/2Q22Y6a
JMeter Tips & Tricks - bit.ly/2NOfWD2
Performance Testing - bit.ly/2wEXbLS
----------- PROGRAMMING -----------
Java Beginners - bit.ly/2PVUcXs
Java Tips & Tricks - bit.ly/2CdcDnJ
GROOVY - bit.ly/2FvWV5C
JAVASCRIPT - bit.ly/2KJDZ8o
PYTHON - bit.ly/2Z4iRye
----------- IDE -----------
Visual Studio Code - bit.ly/2V15yvt
----------- BUILD TOOLS -----------
Maven - bit.ly/2NJdDRS
Gradle - bit.ly/30l3h1B
----------- OTHERS -----------
Redis- bit.ly/2N9jyCG
Misc - bit.ly/2Q2q5xQ
Tools & Tips - bit.ly/2oBfwoR
QnA Friday- bit.ly/2NgwGpw
Sunday Special - bit.ly/2wB23BO
Ask Raghav - bit.ly/2CoJGWf
Interviews - bit.ly/2NIPPxk
All Playlists - bit.ly/2LSiezA
---------- Connect with Raghav -----------
Udemy Courses - www.udemy.com/user/raghav-pal-3/
Twitter - / learnwithraghav
KZfaq - / automationstepbystep
Never Stop Learning
Raghav

Пікірлер: 40
@jatingirdhar1589
@jatingirdhar1589 4 ай бұрын
Hi Raghav sir, I have been reading through all your answers to the comments. You have replied all the questions so patiently, with so much politeness & humbleness. Apart from a great trainer, I would say, you are a great human being too. Hats off to all your values & talent ! 😍😗
@RaghavPal
@RaghavPal 4 ай бұрын
Thanks a lot for your kind words Jatin.. humbled
@gabrielfrank6618
@gabrielfrank6618 Жыл бұрын
Thankyou for detailed & easy understanding of ur Tutorials !!
@RaghavPal
@RaghavPal Жыл бұрын
Most welcome Gabriel
@roushansingh8895
@roushansingh8895 Жыл бұрын
Good one content 🤟🤟🙏🙏
@RaghavPal
@RaghavPal Жыл бұрын
Thank you
@rathishravi2314
@rathishravi2314 Жыл бұрын
Useful
@RaghavPal
@RaghavPal Жыл бұрын
Glad to hear that
@vargabghosh5497
@vargabghosh5497 2 жыл бұрын
nice video sir
@RaghavPal
@RaghavPal 2 жыл бұрын
Thanks a lot Vargab
@shahzaibidreesahmed4827
@shahzaibidreesahmed4827 Жыл бұрын
Great explanation 👌Sir why and when do we use variables and what is the advantage of variables you said in this video it is used for time-saving, could you please give some physical examples?
@RaghavPal
@RaghavPal Жыл бұрын
Hi Shahzaib Variables in Postman are used to store values that can be used in requests and responses. They can be used to store: * Static values, such as the URL of a web service or the name of a user * Dynamic values, such as the current date and time or the value of a form field Variables can be used to: * Make requests more reusable. By storing values in variables, you can use the same request for different values. For example, you could create a request that uses a variable to store the URL of a web service. You could then use that request to send requests to different web services by simply changing the value of the variable * Make requests more maintainable. By storing values in variables, you can isolate the values from the request itself. This makes it easier to change the values without having to change the request. For example, if you need to change the URL of a web service, you can simply change the value of the variable in the request. You don't need to change the request itself * Save time. By using variables, you can avoid having to type the same values over and over again. For example, if you need to send a request to a web service 10 times, you could use a variable to store the URL of the web service. You would then only need to type the variable name in the request 10 times Here are some physical examples of how variables can be used in Postman: * You can use a variable to store the name of a user. You can then use this variable to populate a form field in a request * You can use a variable to store the current date and time. You can then use this variable to add a timestamp to the response of a request * You can use a variable to store the value of a form field. You can then use this variable to make a request to a web service Overall, variables can be a very useful tool in Postman. They can be used to make requests more reusable, maintainable, and time-saving
@shahzaibidreesahmed4827
@shahzaibidreesahmed4827 Жыл бұрын
@@RaghavPal Thank you!
@heenashaikh3350
@heenashaikh3350 Жыл бұрын
Hi.. Can u plz provide explanation on authorization in postman and why and from where do we need tokenization as this was asked in my interview. How and from where do we copy paste the token in authorization
@RaghavPal
@RaghavPal Жыл бұрын
Hi Heena Sure. Authorization in Postman is a way to control who has access to a particular API. There are a few different ways to authorize requests in Postman, including Basic Auth, Bearer Token Auth, OAuth 2.0, and API Key Auth. **Basic Auth:** Basic Auth is the simplest form of authorization. It uses a username and password to authenticate the user. To use Basic Auth in Postman, simply enter your username and password in the Authorization tab. **Bearer Token Auth:** Bearer Token Auth is a more secure form of authorization. It uses a token to authenticate the user. Tokens are typically generated by the API provider and are used to access the API. To use Bearer Token Auth in Postman, simply enter your token in the Authorization tab. **OAuth 2.0:** OAuth 2.0 is a popular authorization protocol. It allows users to grant third-party apps access to their data without giving away their passwords. To use OAuth 2.0 in Postman, you will need to create a client ID and client secret from the API provider. Once you have your client ID and client secret, you can enter them in the Authorization tab. **API Key Auth:** API Key Auth is a way to authenticate users by using a secret key. API keys are typically generated by the API provider and are used to access the API. To use API Key Auth in Postman, simply enter your API key in the Authorization tab. Tokenization is the process of converting sensitive data into a more secure format. This can be done by using a hash function or a cipher. Tokenization is often used to protect passwords, credit card numbers, and other sensitive data. In Postman, tokenization can be used to protect your API keys and tokens. To tokenize your API key or token, simply click on the "Tokenize" button in the Authorization tab. Postman will then generate a token for you. You can then use this token to access the API without having to worry about exposing your API key or token. To copy and paste a token in Postman, simply click on the "Copy" button next to the token. You can then paste the token into the Authorization tab of another request. hope this helps
@fouried96
@fouried96 7 ай бұрын
Hi, thanks for the video! The one priority variable you didnt show was Data, how would we set and get Data variables, and in what context are Data variables used? Thanks!
@fouried96
@fouried96 7 ай бұрын
Never mind, I see you explained this in video 13 in this playlist series👍🏻
@RaghavPal
@RaghavPal 7 ай бұрын
All the best
@inshort5341
@inshort5341 Жыл бұрын
how long the variables are valid - the local ones ? Do they expire after a call ?
@RaghavPal
@RaghavPal Жыл бұрын
Hi, In Postman, local variables are valid only for the duration of a single Postman session. This means that local variables are not persistent and will not survive between different Postman sessions or different API calls within the same session. When you make an API call, any local variables that you have set will be available for use in that particular API call. Once the API call is completed, the local variables will no longer be available for use in subsequent calls.
@gudipatisai6337
@gudipatisai6337 Жыл бұрын
one question here raghav in which cases which variables will be used can you pls explain us in detail?? @Automation Step by Step
@RaghavPal
@RaghavPal Жыл бұрын
I will plan a session on this
@nahlaelnayal8644
@nahlaelnayal8644 Жыл бұрын
@@RaghavPal yes please, I am waiting for this session, thanks a lot sir.
@vidhirathi5705
@vidhirathi5705 11 ай бұрын
Could you please clarify why "Newton" was returned as the name value even after unsetting the environment variable? Referring to Tutorial 8 at 12:02
@RaghavPal
@RaghavPal 11 ай бұрын
Hi Vidhi That is because the script to print name is executed before the script that unsets the variable
@vidhirathi5705
@vidhirathi5705 11 ай бұрын
@@RaghavPal what if I re-run? Should that still be the same?
@RaghavPal
@RaghavPal 11 ай бұрын
if the variable is being created or set within the script, it will be created and then removed, else not
@akhilkulkarni3130
@akhilkulkarni3130 2 ай бұрын
Where should I see the Local variable is saved or not?
@RaghavPal
@RaghavPal 2 ай бұрын
Akhil Local variables in Postman are temporary variables that are accessed within the context of a specific request or script. They are scoped to a single request or collection run and are no longer available once the run is complete. Here's where you can find and manage local variables in Postman: 1. Request-Level Local Variables: - Local variables are set within a specific request or script. - To view and manage local variables for a particular request: - Open the request in Postman. - Go to the "Pre-request Script" or "Tests" tab. - Any variables defined here are local to that request. - You can use them within the request itself or in subsequent test scripts. 2. Collection-Level Local Variables: - Collection-level local variables are accessible only within the scope of the collection run. - They are independent of environments and do not change based on the selected environment. - To manage collection-level local variables: - Click on the collection folder in the left sidebar. - Go to the "Variables" tab within the collection. - Here, you can define and manage local variables that apply to all requests within that collection. Remember that local variables are temporary and are discarded once the request or collection run is complete. They are useful for passing data between pre-request scripts, requests, and tests within a specific context. If you're looking for more persistent variables, consider using environment variables or global variables instead.
@akhilkulkarni3130
@akhilkulkarni3130 2 ай бұрын
@@RaghavPal Thanks
@alihamza-eb2yy
@alihamza-eb2yy Жыл бұрын
Why do we use Get and set Variable?Where we use it
@RaghavPal
@RaghavPal Жыл бұрын
Hi, we can use variables to store values and use them later, these values can be extracted from response and be used in next requests or within the scripts
@moodoffbhubaneswar5486
@moodoffbhubaneswar5486 Жыл бұрын
Sir why get and set came into picture...
@RaghavPal
@RaghavPal Жыл бұрын
this is to read and create variables through scripts
@cricboyz7743
@cricboyz7743 Жыл бұрын
actually mine name is not updated in collection like ramanujan
@RaghavPal
@RaghavPal Жыл бұрын
will need to check again
@cricboyz7743
@cricboyz7743 Жыл бұрын
hello sir
@RaghavPal
@RaghavPal Жыл бұрын
Hi
@khanhhuyen8641
@khanhhuyen8641 Жыл бұрын
I can not do "console.." , it just appeared undefined
@RaghavPal
@RaghavPal Жыл бұрын
Hi Khánh The `console` object is not available in Postman. Postman is a tool for testing APIs, and it does not have the same functionality as a web browser. If you want to use the `console` object, you can use a web browser to test your API. When you send a request to your API in a web browser, the `console` object will be available in the browser's developer tools. Here are the steps on how to use the `console` object in a web browser: 1. Open the web browser and navigate to the URL of your API. 2. Open the developer tools. In Chrome, you can open the developer tools by pressing `Ctrl`+`Shift`+`I`. 3. In the developer tools, go to the "Console" tab. 4. When you send a request to your API, the response will be displayed in the console. 5. You can use the `console` object to inspect the response. Here are some examples of how to use the `console` object in a web browser: ``` console.log(response); console.dir(response); console.table(response); ``` The `log()` method will print the response to the console. The `dir()` method will print a detailed view of the response to the console. The `table()` method will print the response in a table format to the console
Postman Beginner Tutorial 9 | Environments
12:15
Automation Step by Step
Рет қаралды 45 М.
Русалка
01:00
История одного вокалиста
Рет қаралды 5 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 55 МЛН
Loop request based on data from response in Postman
13:13
Valentin Despa
Рет қаралды 57 М.
Postman Beginner Tutorial 4 | PUT PATCH API Request
6:25
Automation Step by Step
Рет қаралды 84 М.
Postman Beginner Tutorial 7 | How to add and refer Variables
9:02
Automation Step by Step
Рет қаралды 52 М.
Postman Beginner Tutorial 11 | How to create First Test
4:39
Automation Step by Step
Рет қаралды 35 М.
#7 How to Get variables and Set variables in Postman through scripting
12:26
Suresh SDET Automation
Рет қаралды 1,6 М.
How to Use Variables in Postman
10:41
Postman
Рет қаралды 37 М.
Postman Api Testing Tutorial for beginners
16:45
Codemify
Рет қаралды 20 М.