postmanlabs / newman

Newman is a command-line collection runner for Postman
https://www.postman.com
Apache License 2.0
6.78k stars 1.15k forks source link

Access cookies in Cookiejar #3198

Open aryalakshmi opened 5 months ago

aryalakshmi commented 5 months ago

Version and environment information: -->

  1. Newman Version (can be found via newman -v):6.1.0
  2. OS details (type, version, and architecture): Windows 10
  3. Are you using Newman as a library, or via the CLI? Library
  4. Did you encounter this recently, or has this bug always been there: Always
  5. Expected behaviour: Unable to access cookies obtained from Postman interceptor using Cookiejar
  6. Command / script used to run Newman: node WriteTofile.js (https://gist.github.com/aryalakshmi/4040e68a9b7a6253d467c846ccba9c45)
  7. Sample collection, and auxiliary files (minus the sensitive details):
  8. Screenshots (if applicable):

Steps to reproduce the problem:

  1. Trying to automate all APIs for a router webgui
  2. Fetching 3 cookies using Postman interceptor called cookie1, cookie2 and lang
  3. use cookieJar and access cookies in Tests of Request 1. Set it as a Header. Set cookie as a collectionvariable
  4. Use the cookies in Request2
  5. Run collection from POSTMAN -> Success
  6. Export collection and run using newman library -> Cookiejar unable to fetch the cookies

Codesnippet of Request1: const cookieJar = pm.cookies.jar(); const url = 'http://192.168.x.1' cookieJar.getAll(url, (error, cookies) => { if (error) { console.error(error); } else { console.log(cookies); =>Newman returns this as EMPTY const cookie1Value = cookies.find(cookie => cookie.name === "cookie1").value;

} });

May i know if there is any way to access cookies in cookiejar or any other way to access the cookies. Note: These cookies are not accessible in any API response also.