No matter what I do I get an error (either X.cookies is not a function or X.addCookies is not a function). I tried with context, page.context. browserContext etc. and it always ends up in the same way (ok, page.context as well as browserContext are undefined so error is different).
Context:
Code:
beforeEach(async function fn() {
this.timeout(20000);
browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
page = await context.newPage();
await page
.goto("http://localhost:4200/#/login", {
waitUntil: "networkidle0",
})
.catch(() => {});
});
and in test:
await context.addCookies([
{ name: "csrftoken", value: cookieToken, path: "/" },
{ name: "sessionid", value: cookieSession, path: "/" },
]);
await context.cookies();
I had to use context directly instead of browser context, otherwise some data would not load correctly (specifically in a SvelteKit app):
test('index page has expected content when logged in', async ({ page, context }) => {
await context.addCookies([
{ name: 'sessionid', value: 'random', path: '/', domain: 'localhost' }
]);
await page.goto('/');
expect(await page.textContent('h1')).toBe('My title');
console.log(await context.cookies());
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With