Rayrun
โ† Back to Discord Forum

Created cookies aren't found

Hi All!

I'm trying to figure out why context.cookies can't find some cookies I've created with context.addcookies.

They're created with these properties: {name: somename, value: somevalue, domain: somedomain} & context.cookies(url) is used to find them. It finds all the other cookies stored in the storagestate json file but not these ones.

A couple of questions

  1. Should cookies that have been added this way actually show in browser devtools?
  2. When creating the cookies does the domain have to be real? Silly question I know but it's no doubt important! I've tried real & not real & there's no difference...

Any help or advice is appreciated as always! ๐Ÿ™

This thread is trying to answer question "Why can't context.cookies find some cookies created with context.addcookies?"

7 replies

Hey ๐Ÿ‘‹ ,

I'm not 100% positive but when i use storageState

storageState: 'storage-state.json',
    /* Base URL to use in actions like `await page.goto('/')`. */
    // baseURL: 'http://127.0.0.1:3000',

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'retain-on-failure',
  },

In my playwright.config.js it does load and shows in the browser(How i get around logging in every time).

Thanks, that helps a little. I'll tinker with our state storage a little - I know it's not specified from within the config file so maybe that is causing some issue

๐Ÿ‘ Let me know how it goes!

Thank you, will do!

refactoreric

A possible source of confusion is that each test runs with its own isolated browser context, so the cookies won't carry over to the next test, unless they are in the storage state. This is all assuming that you are using the page or context fixture like the typical @playwright/test samples from the web site.

๐Ÿ‘ I did wonder whether it was using the wrong context or pointing at the wrong users storage state file. It did seem to give the correct cookies for that user though. In the test should it need a test.use({storagestate: etc}) for the logged in user or the user to retrieve cookies for, or both? Can it even do both?

I don't understand your situation. What are you trying to achieve with all of this? What do you mean with "logged in user" vs "user to retrieve cookies for"? In most cases I'd say they're the same user.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.