diff --git a/frontend/.gitignore b/frontend/.gitignore index a6e21743cf..20b562a0b6 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -24,3 +24,4 @@ src/lib/components/copilot/chat/__tests__/app/results/ /blob-report/ /playwright/.cache/ /playwright/.auth/ +e2e/auth.json \ No newline at end of file diff --git a/frontend/e2e/dbmanager.spec.ts b/frontend/e2e/dbmanager.spec.ts new file mode 100644 index 0000000000..f546f40e1e --- /dev/null +++ b/frontend/e2e/dbmanager.spec.ts @@ -0,0 +1,6 @@ +import { test, expect } from '@playwright/test' + +test('has Home text', async ({ page }) => { + await page.goto('/') + await expect(page.locator('text=Home').first()).toBeVisible() +}) diff --git a/frontend/e2e/login.spec.ts b/frontend/e2e/global-setup.ts similarity index 63% rename from frontend/e2e/login.spec.ts rename to frontend/e2e/global-setup.ts index 5674cbe054..38098e37e7 100644 --- a/frontend/e2e/login.spec.ts +++ b/frontend/e2e/global-setup.ts @@ -1,7 +1,14 @@ -import { test, expect } from '@playwright/test' +// global-setup.ts +import { chromium, FullConfig } from '@playwright/test' -test('log in correctly', async ({ page }) => { - await page.goto('/') +async function globalSetup(config: FullConfig) { + const browser = await chromium.launch() + const context = await browser.newContext() + const page = await context.newPage() + + // Use baseURL from config + const baseURL = config.projects[0].use.baseURL || 'http://localhost:3000' + await page.goto(baseURL) // Wait for and fill the email input const emailInput = page.locator('input#email[type="email"]') @@ -13,10 +20,6 @@ test('log in correctly', async ({ page }) => { await passwordInput.waitFor({ state: 'visible' }) await passwordInput.fill('changeme') - // Verify the inputs are filled correctly - await expect(emailInput).toHaveValue('admin@windmill.dev') - await expect(passwordInput).toHaveValue('changeme') - // Click the sign-in button const signInButton = page.locator('button:has-text("Sign in")') await signInButton.click() @@ -30,17 +33,19 @@ test('log in correctly', async ({ page }) => { // Wait for navigation to workspaces page await page.waitForURL('**/user/workspaces') - await expect(page).toHaveURL(/\/user\/workspaces$/) // Click on the "Admins" workspace const adminsWorkspace = page.locator('text=Admins').first() await adminsWorkspace.waitFor({ state: 'visible' }) await adminsWorkspace.click() - // Verify we're on the root path of the workspace + // Wait for workspace to load await page.waitForURL('**/') - await expect(page).toHaveURL(/\/$/) + await page.locator('text=Home').first().waitFor({ state: 'visible' }) - // Wait for the page to load and verify it contains "Home" - await expect(page.locator('text=Home').first()).toBeVisible() -}) + // Save the authenticated state + await context.storageState({ path: './e2e/auth.json' }) + await browser.close() +} + +export default globalSetup diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index 51210c33bf..4be806968e 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -12,6 +12,7 @@ import { defineConfig, devices } from '@playwright/test' * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ + globalSetup: './e2e/global-setup', testDir: './e2e', /* Run tests in files in parallel */ fullyParallel: true, @@ -29,7 +30,9 @@ export default defineConfig({ baseURL: process.env.BASE_URL || 'http://localhost:3000', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry' + trace: 'on-first-retry', + + storageState: './e2e/auth.json' }, /* Configure projects for major browsers */