Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using cookie data #664

Closed
abhijitkane opened this issue Jul 30, 2014 · 6 comments
Closed

Using cookie data #664

abhijitkane opened this issue Jul 30, 2014 · 6 comments
Labels
platform/chrome Chrome app specific issues

Comments

@abhijitkane
Copy link
Member

Justin Hooks • 20 hours ago

I’ve been using Postman and Newman to great success recently,
but have come upon a big stumbling block. I'm on a software QA team in Houston,
Texas, and I really need to set a website session ID, stored in a cookie, as an
environment variable for a collection of GET requests I'm working with. I’ve
downloaded the Interceptor plugin and I thought it would accomplish what I
need, but I’m having some difficulty. I need the environment variable from the
cookie to be used in my Postman Auth headers when I run the collection. Is it
possible to capture the session ID from the cookie like this? I'd appreciate
any help. thanks!

@abhijitkane
Copy link
Member Author

I'm guessing this is not a one time thing, and you want to automate it.
You want to automate a flow where you send a request to an existing website, capture the cookie, and use the cookie value (after parsing) in your own API request.
Is my understanding correct?

@msajedi
Copy link

msajedi commented Aug 11, 2014

I have the same problem. I need to extract the session ID as well as authentication token from cookie.

@morpheus7xx
Copy link

Hey everyone, sorry for the late response. I've actually had some progress on this issue, but it has created another issue. We were able to hard code a kind of HTML scrape that would pull the Session ID and assign it as a variable, which is then used in tandem with the Password field to hash the Basic Auth and allow us to continue our testing. We've found this method works every time in the Collection Runner but fails in Newman. Here is the code we used:

var index1 = responseBody.indexOf("SID__=");
var strSubstring = responseBody.substring(index1 + 6, 100);
var index2 = strSubstring.indexOf(" ");
var SID = strSubstring.substring(0, index2);
var strBase64 = btoa("ca_Justin.Hooks" + ':' + SID);
var auth = 'Basic ' + strBase64;
postman.setEnvironmentVariable("colhub_auth", auth);

@ejohnson-spritz
Copy link

I am trying to accomplish pretty much the same thing. I send a post request and in the response body to that request I get some values which I need, but there is a value returned in a cookie that I also need which is a session id . The session id I want to store in an environment variable so that I can chain a set of request together for automation purposes through newman. I am sure there should be a way to parse the information out of the cookie but I am not sure how to do this through postman/jetpacks. Suggestions?

@a85 a85 added the platform/chrome Chrome app specific issues label Jan 20, 2015
@mverma-va
Copy link

Can someone please update the best solution here??

@abhijitkane
Copy link
Member Author

@ejohnson-spritz @mverma-va With the Interceptor on, you should have access to the cookies in the test script - postman.getResponseCookie(cookieName). Check https://www.getpostman.com/docs/jetpacks_sandbox and http://blog.getpostman.com/2014/11/28/using-the-interceptor-to-read-and-write-cookies/.

@a85 a85 closed this as completed Sep 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform/chrome Chrome app specific issues
Projects
None yet
Development

No branches or pull requests

6 participants