adding cookies to configuration file in cypress

Our environments are defined by cookies for example with cookie env=dev

QA environment with cookie env=qa

PROD environment with cookie env=prod
  1. How to create the config file in Cypress to access these environments.
  2. If I want to configuration by cookie + user agent (ex: with cookie env=qa and useragent='Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1'. What is the best way to configure the configuration file.

1 Answer

  1. Francis- Reply


    The Best way to accomplish this in my opinion would be add a json file under your cypress\fixtures for example you added cookies.json in your fixtures directory, here's how you'd then access it:

    1st way


    2nd way

    cy.fixture('cookies.json').then((cookies) => {
    // now you have access to cookies object to manipulate

    here is more info on fixtures from docs hope this helps

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>