-
-
Save idubrov/d8b06800bed48ebb41465a219a7908a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cy.task("GoogleSocialLogin", socialLoginOptions).then(({ cookies }) => { | |
const googleCookies = cookies.filter( | |
(cookie) => cookie.domain === ".google.com" || cookie.domain === "accounts.google.com" || cookie.domain === ".youtube.com" | |
); | |
cy.intercept( | |
{ | |
url: /^http:\/\/localhost:3002\/cypress-cookies\//, | |
}, | |
(req) => { | |
const pos = req.url.lastIndexOf("/"); | |
const index = req.url.substring(pos + 1); | |
const domain = googleCookies[index].domain; | |
const url = domain.startsWith(".") ? domain.substring(1) : domain; | |
req.reply(200, `<!DOCTYPE html><html><script>window.location = 'https://cypress-cookies.${domain}/${index}';</script></html>`, { | |
"Content-Type": "text/html", | |
}); | |
} | |
); | |
cy.intercept( | |
{ | |
url: /^https:\/\/cypress-cookies\.*/, | |
}, | |
(req) => { | |
const pos = req.url.lastIndexOf("/"); | |
const index = parseInt(req.url.substring(pos + 1), 10); | |
req.reply(200, "<!DOCTYPE html><html><script>window.location = 'http://localhost:3002/cypress-cookies-end/';</script></html>", { | |
"Content-Type": "text/html", | |
"Set-Cookie": serializeCookie(googleCookies[index]), | |
}); | |
} | |
); | |
cy.intercept( | |
{ | |
url: /^http:\/\/localhost:3002\/cypress-cookies-end/, | |
}, | |
(req) => { | |
req.reply(200, "<!DOCTYPE html><html></html>", { | |
"Content-Type": "text/html", | |
}) | |
} | |
); | |
// Set all the cookies, one by one. | |
// FIXME: is there a way to set multiple cookies at once? Cypress only allows setting one header at a time. | |
for (let index = 0; index < googleCookies.length; index += 1) { | |
cy.visit(`http://localhost:3002/cypress-cookies/${index}`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment