Skip to content

Commit

Permalink
test: unflake some cookie tests in msedge (#34217)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Jan 5, 2025
1 parent 5a22475 commit eeca68b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/library/defaultbrowsercontext-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ import { playwrightTest as it, expect } from '../config/browserTest';
import { verifyViewport } from '../config/utils';
import fs from 'fs';

it('context.cookies() should work @smoke', async ({ server, launchPersistent, defaultSameSiteCookieValue }) => {
function maybeFilterCookies(channel: string | undefined, cookies: any[]) {
if (channel?.startsWith('msedge'))
return cookies.filter(c => !c.domain.endsWith('microsoft.com'));
return cookies;
}

it('context.cookies() should work @smoke', async ({ server, launchPersistent, defaultSameSiteCookieValue, channel }) => {
const { page } = await launchPersistent();
await page.goto(server.EMPTY_PAGE);
const documentCookie = await page.evaluate(() => {
document.cookie = 'username=John Doe';
return document.cookie;
});
expect(documentCookie).toBe('username=John Doe');
expect(await page.context().cookies()).toEqual([{
expect(maybeFilterCookies(channel, await page.context().cookies())).toEqual([{
name: 'username',
value: 'John Doe',
domain: 'localhost',
Expand All @@ -39,7 +45,7 @@ it('context.cookies() should work @smoke', async ({ server, launchPersistent, de
}]);
});

it('context.addCookies() should work', async ({ server, launchPersistent, browserName, isWindows }) => {
it('context.addCookies() should work', async ({ server, launchPersistent, browserName, isWindows, channel }) => {
const { page } = await launchPersistent();
await page.goto(server.EMPTY_PAGE);
await page.context().addCookies([{
Expand All @@ -49,7 +55,7 @@ it('context.addCookies() should work', async ({ server, launchPersistent, browse
sameSite: 'Lax',
}]);
expect(await page.evaluate(() => document.cookie)).toBe('username=John Doe');
expect(await page.context().cookies()).toEqual([{
expect(maybeFilterCookies(channel, await page.context().cookies())).toEqual([{
name: 'username',
value: 'John Doe',
domain: 'localhost',
Expand All @@ -61,7 +67,7 @@ it('context.addCookies() should work', async ({ server, launchPersistent, browse
}]);
});

it('context.clearCookies() should work', async ({ server, launchPersistent }) => {
it('context.clearCookies() should work', async ({ server, launchPersistent, channel }) => {
const { page } = await launchPersistent();
await page.goto(server.EMPTY_PAGE);
await page.context().addCookies([{
Expand All @@ -76,7 +82,7 @@ it('context.clearCookies() should work', async ({ server, launchPersistent }) =>
expect(await page.evaluate('document.cookie')).toBe('cookie1=1; cookie2=2');
await page.context().clearCookies();
await page.reload();
expect(await page.context().cookies([])).toEqual([]);
expect(maybeFilterCookies(channel, await page.context().cookies([]))).toEqual([]);
expect(await page.evaluate('document.cookie')).toBe('');
});

Expand Down

0 comments on commit eeca68b

Please sign in to comment.