Set a cookie for a test

I want to set a cookie for a test, which I try to do via a pre-request script.
I have set an environment variable for the value I want to set (on multiple tests) and have this pre-request script:

const cookieJar = pm.cookies.jar();
authcookie = pm.environment.get(“auth-cookie”);
console.log(authcookie);
cookieJar.clear(‘https://myserver.com/’, function (error) { console.log(error); });
cookieJar.set(‘https://myserver.com/’,
{ “name”: “PHPSESSID”, “value”: authcookie, “httpOnly”: false },
function (error, cookie) { console.log(error); });

When I run the script, I get this error which I have no idea how to solve:

Object {message: “CookieStore: programmatic access to “myserver.com” is denied”, name: “Error”, type: “Error”}

  1. message: “CookieStore: programmatic access to “myserver.com” is denied”
  2. name: “Error”
  3. type: “Error”

Any idea how to solve that?

Update: I am trying this in the Postman app on mac.

2 Likes

Did you ever find a solution to your question?

No, not really. I implemented a workaround where postman now has a workaround to authenticate itself so the session cookie can get setup using the regular way.

Zap.

I solved this by following these instructions (" Whitelisting domains for programmatic access of cookies"):

https://learning.getpostman.com/docs/postman/sending-api-requests/cookies/#whitelisting-domains-for-programmatic-access-of-cookies

Note: the ‘Whitelist Domains’ button might not be visible, I had to close a message about an Interceptor Lesson in the ‘Manage Cookies’ popup to see it.

After whitelisting your domain you’ll be able to manage the cookies.

2 Likes