question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set an environment variable in the previous request and then pass it into the following request?

See original GitHub issue
  1. Newman Version (can be found via newman -v): 3.6.0
  2. OS details (type, version, and architecture): windows7
  3. Are you using Newman as a library, or via the CLI? via CLI
  4. Did you encounter this recently, or has this bug always been there: just started to use newman recently
  5. Expected behaviour: I am expecting the environment variable get set during request1 then from request2, I can pass in the value into the header
  6. Command / script used to run Newman: newman run collection.json -e env.json
  7. Sample collection, and auxilliary files (minus the sensitive details): I am running the following collection from command line and having an env json exported with base_url and cookie, the cookie value is set during the first request run. Can I do the following to get the environment variable set and pass along?
{
	"variables": [],
	"info": {
		"name": "Sophie",
		"_postman_id": "1eb379e2-2e4e-6c43-c72e-1127cd3e1f0b",
		"description": "Sophie's Test",
		"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
	},
	"item": [
		{
			"name": "get",
			"description": "",
			"item": [
				{
					"name": "login",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"tests[\"Status code is 200\"] = responseCode.code === 200;",
									"postman.setEnvironmentVariable(\"cookie\", \"loginSession=\"+postman.getResponseCookie(\"loginSession\").value);",
									""
								]
							}
						}
					],
					"request": {
						"url": "http://{{base_url}}/sophie_ui/",
						"method": "GET",
						"header": [
							{
								"key": "Accept",
								"value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
								"description": ""
							}
						],
						"body": {},
						"description": ""
					},
					"response": []
				},
				{
					"name": "login with username/pwd",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"tests[\"Status code is 200\"] = responseCode.code === 200;"
								]
							}
						}
					],
					"request": {
						"url": "http://{{base_url}}/login/security_check",
						"method": "POST",
						"header": [
							{
								"key": "Cookie",
								"value": "{{**cookie**}}",
								"description": ""
							}
						],
						"body": {
							"mode": "raw",
							"raw": "j_username=&j_password="
						},
						"description": ""
					},
					"response": []
				}
			]
		}
	]
}
  1. Screenshots (if applicable):

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sophiecddcommented, May 17, 2017

And also, same question as I asked on the closed thread earlier yesterday. Since the value of that environmental parameter is change dynamically, is it possible that the following test case is not getting the updated value?

0reactions
RonakReyhanicommented, Apr 22, 2019

Hey guys , I went through the issue and didn’t get a proper solution , however this ticket had been closed. this is my Newman response : in first request it gets the stock id and creates an order for that, when it gets the order, request still using the old value of orderId, while it has to use “01646” . how can I pass this value to my global environment ? instead of using old value? the third test is failing as for it can’t find old order id!

image

this is my newman run command:
newman run IntegrationTests.postman_collection.json -e IntegrationTests_DEV.postman_environment.json -g IntegrationTests_Dev.postman_globals.json --export-environment IntegrationTests_DEV.postman_environment.json export-global IntegrationTests_Dev.postman_globals.json

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update environment variables based on a ... - YouTube
Sometimes, the response from a request is required first in order to continue with all the other API requests currently stored in your ......
Read more >
How To Set Environment Variables - Twilio
In the new window that opens, click on the Advanced tab and afterwards on the Environment Variables button in the bottom right of...
Read more >
Extracting Data from Responses and Chaining Requests
For this example, we'll create and set a blank test environment. ... Let's add a form-data variable to the '/status' request.
Read more >
Environment variables set by HTTP Server - IBM
Variable Name Type Description QZHBIS_CLUSTER_ENABLED Non‑SSL REDIRECT_QUERY_URL Non‑SSL HTTPS_SESSION_ID SSL Set to NULL by default when used with HTTP Ser...
Read more >
Use environment variables | Cloud Run Documentation
When you set environment variables, they are injected into the container and are accessible to your code. Environment variables are set as key/value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found