adding cookies to configuration file in cypress

Our environments are defined by cookies for example

www.cypress.com with cookie env=dev

QA environment
www.cypress.com with cookie env=qa

PROD environment
www.cypress.com 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: www.cypress.com 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

    2019-11-16

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

    1st way

    cy.fixture('cookies.json').as('cookies');
    cy.get('@cookies');
    

    2nd way

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

    here is more info on fixtures from cypress.io docs https://docs.cypress.io/api/commands/fixture.html#Usage 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>