'Cypress Chrome Extension only sets cookie on start, not subsequent page loads
I have a pretty basic Chrome Extension setup which just sets an empty cookie value on page load when on a specific URL. This all works fine in the actual Chrome browser, but when running the extension within a Cypress test it only sets the cookie once, when the cypress tests start.
My cypress test visits 3 URLs on a site, but the cookie isn't set to the empty value specified in my chrome extension.
Chrome Extension Code:
setCookie( 'xbc', '', 30 );
function setCookie( cName, cValue, expDays ) {
let date = new Date();
date.setTime( date.getTime() + ( expDays * 24 * 60 * 60 * 1000 ) );
const expires = "expires=" + date.toUTCString();
document.cookie = cName + "=" + cValue + "; " + expires + "; domain=.site-url.com";
}
Test Code:
describe( 'Test the chrome extension', () => {
it( 'Hides popup', () => {
cy.visit( 'https://site-url.com/crime/' );
cy.get( '.asset-type-article:nth-child(1) .headline' ).click();
cy.visit( 'https://site-url.com/crime/' );
cy.get( '.asset-type-article:nth-child(2) .headline' ).click();
cy.visit( 'https://site-url.com/crime/' );
cy.get( '.asset-type-article:nth-child(3) .headline' ).click();
} );
} );
After the cypress test runs, the popup displays and the xbc cookie value is not empty. Is this a limitation with Cypress and how it runs in an iframe?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
