Skip to content

Commit d6d7f73

Browse files
committed
test(e2e): add cookie banner test for production pages
1 parent a047f1b commit d6d7f73

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect, test as base } from '@playwright/test';
2+
import { skipNonProduction } from '../utils';
3+
4+
skipNonProduction('Cookie banner only on production');
5+
6+
const test = base.extend({
7+
page: async ({ browser }, use) => {
8+
const context = await browser.newContext({
9+
storageState: undefined
10+
});
11+
const page = await context.newPage();
12+
13+
await use(page);
14+
15+
await page.close();
16+
await context.close();
17+
}
18+
});
19+
20+
test.describe('Cookie banner functionality', () => {
21+
const PAGE_TYPES_EXAMPLE = [
22+
'/',
23+
'/docs/getting-started.html',
24+
'/docs/multiplatform/get-started.html',
25+
'/api/core/kotlin-stdlib/',
26+
'/api/kotlinx.coroutines/kotlinx-coroutines-core/',
27+
'/lp/multiplatform/case-studies/autodesk/'
28+
];
29+
30+
for (const path of PAGE_TYPES_EXAMPLE) {
31+
test(`Cookie banner should be visible and closeable: ${path}`, async ({ page, baseURL }) => {
32+
await page.goto(`${baseURL}${path}`);
33+
34+
const acceptButton = page.getByRole('button', { name: 'Accept All' });
35+
await expect(acceptButton).toBeVisible({ timeout: 10000 });
36+
37+
await acceptButton.click();
38+
await expect(acceptButton).toBeHidden({ timeout: 3000 });
39+
40+
const cookies = await page.context().cookies();
41+
expect(cookies.length).toBeGreaterThan(0);
42+
});
43+
}
44+
});

test/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, Locator, Page } from '@playwright/test';
1+
import { expect, Locator, Page, test } from '@playwright/test';
22
import { PageAssertionsToHaveScreenshotOptions } from 'playwright/types/test';
33

44
export const testSelector = (name: string) => `[data-test="${name}"]`;
@@ -35,3 +35,7 @@ export function isProduction(baseURL: string | undefined) {
3535
return false;
3636
}
3737
}
38+
39+
export function skipNonProduction(message: string) {
40+
test.skip(({ baseURL }) => !isProduction(baseURL), message);
41+
}

0 commit comments

Comments
 (0)