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

Add capability to observe the cookie state #4428

Closed
miherlosev opened this issue Oct 28, 2019 · 7 comments
Closed

Add capability to observe the cookie state #4428

miherlosev opened this issue Oct 28, 2019 · 7 comments
Labels
TYPE: enhancement The accepted proposal for future implementation.

Comments

@miherlosev
Copy link
Collaborator

miherlosev commented Oct 28, 2019

TestCafe uses the own cookie processing mechanism. It leads to a user cannot see the full cookie list same as in the browser development tools.
image

We need to provide such information. It will be useful for complex authentication cases.

#1721 (comment)

@miherlosev miherlosev added the TYPE: enhancement The accepted proposal for future implementation. label Oct 28, 2019
@alexey-lin
Copy link
Contributor

#4425

@austinhinderer
Copy link

I'm still hitting this issue at the end of 2020. Unable to read httpOnly cookies in testCafe.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Dec 18, 2020
@Farfurix
Copy link
Contributor

@austinhinderer

Hello,

Unfortunately, I cannot give you any time estimates on when this enhancement will be addressed.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Dec 21, 2020
@deepaneela
Copy link

It will be helpful to have this feature which will get all the cookies including httpOnly, secure basically all cookies we see in dev tools.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 25, 2021
@AlexSkorkin AlexSkorkin removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 26, 2021
@Farfurix Farfurix self-assigned this Aug 26, 2021
@jamesyoung1337
Copy link

For the moment, you can use a work-around to access httpOnly cookies:

My answer on Stack Overflow

Here it is again anyway:

import { Selector, RequestLogger } from 'testcafe';

// Want everything from example.com
const logger = RequestLogger(/example.com/, {
   logResponseHeaders: true,
   logResponseBody: true
   // Do not set stringify response body if your response
   // comes as gzip or brotli or whatever, instead you
   // will need to use Node's zlib to unzip it and read it
});

fixture `My test`
   .page `https://example.com`
   .requestHooks(logger);

test(`Log in and retrieve cookies`, async t => {
   
   await t
   // Do things here
   .click(...)

   const requests = logger.requests
   for (const req of requests) {
       console.log('Headers: ', req.response.headers)

       for (const cookie of req.response.headers['set-cookie']) {
          // You will have to parse the cookie yourself
          console.log(cookie)
       }
   }
});

You may need to wrap your code in a promise and await on it, especially if you access the body as JSON like I do in addition to the cookies, otherwise code after this request logger block may be executed before you read the body.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Dec 7, 2021
@Farfurix Farfurix removed the STATE: Need response An issue that requires a response or attention from the team. label Dec 8, 2021
@Farfurix Farfurix removed their assignment Dec 15, 2021
@helen-dikareva
Copy link
Collaborator

An advanced cookie management API was released in v1.19.0. We added new flexible cross-browser methods that allow you to manipulate browser cookies with ease even if they have the HttpOnly flag specified.

The following example demonstrates how to obtain all cookies from all testing pages:

const allCookies =  await t.getCookies();

Learn more about each cookie method in our docs:
getCookies
setCookies
deleteCookies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

9 participants