Skip to content

Commit

Permalink
✅ Add global setup for cookie acceptance in E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sasamuku committed Feb 10, 2025
1 parent 0cda4f4 commit 55a5dee
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions frontend/packages/e2e/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/playwright/.cache/
# Files created when tests are run locally
/tests/vrt/vrt.test.ts-snapshots/top-1-chromium-darwin.png

storageState.json
18 changes: 18 additions & 0 deletions frontend/packages/e2e/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type FullConfig, chromium } from '@playwright/test'

async function globalSetup(config: FullConfig) {
const { baseURL, storageState } = config.projects[0].use
const browser = await chromium.launch()
const page = await browser.newPage()
await page.goto(`${baseURL}/`)

const cookieButton = page.getByRole('button', {
name: 'Accept All Cookies',
})
await cookieButton.click({ timeout: 3000, force: true }).catch(() => {})
await page.context().storageState({ path: storageState as string })

await browser.close()
}

export default globalSetup
2 changes: 2 additions & 0 deletions frontend/packages/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig, devices } from '@playwright/test'

export default defineConfig({
globalSetup: require.resolve('./global-setup'),
testDir: 'tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
Expand All @@ -11,6 +12,7 @@ export default defineConfig({
use: {
baseURL: process.env.URL || 'http://localhost:5173',
trace: 'on-first-retry',
storageState: 'storageState.json',
},

projects: [
Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/e2e/tests/e2e/toolbar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { expect, test } from '@playwright/test'

test.beforeEach(async ({ page }) => {
await page.goto('/')
const cookieButton = page.getByRole('button', {
name: 'Accept All Cookies',
})
await cookieButton.click({ timeout: 3000, force: true }).catch(() => {})
})

test.describe('Desktop Toolbar', () => {
Expand Down
6 changes: 0 additions & 6 deletions frontend/packages/e2e/tests/vrt/vrt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { expect, test } from '@playwright/test'
const screenshot = async (page: Page, targetPage: TargetPage) => {
await page.goto(targetPage.path)

const cookieAcceptButton = page.getByRole('button', {
name: 'Accept All Cookies',
})
if ((await cookieAcceptButton.count()) > 0) {
await cookieAcceptButton.click()
}
await expect(page).toHaveScreenshot({ fullPage: true })
}

Expand Down

0 comments on commit 55a5dee

Please sign in to comment.