0

I am using the following before my test to try and get a cookie value from the request

cy.request({
            method:'GET',
            url:`https://test:test!@mf-test-magento19.test.com/meat/meat-chicken.html`
            })
            .then((response) => {
                cy.getCookie('frontend').should('exist');
            })

However, it only returns the value null as it is not looking at the request only whats in the browser and to which I have not set the baseurl or have a cy.visit() currently. How can I get the value of a cookie in that request?

1

Cookies are in headers, so you need to get them there:

cy.request({
    method:'GET',
    url:`https://test:test!@mf-test-magento19.test.com/meat/meat-chicken.html`
})
.then((response) => {
    const cookies = response.headers['set-cookie'];
    cookies.forEach(cookie => {
        // parse cookies and do what you need with them
    });
})

Something more about this to read:

1
  • 1
    This helped a lot thank you! Also led me to understand what parsing is when I tried to read that cookie value thanks! – Mark Wilson Nov 20 '20 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.