diff --git a/src/frontend/.gitignore b/src/frontend/.gitignore index 4ea574bbeb..2c08d8c2b4 100755 --- a/src/frontend/.gitignore +++ b/src/frontend/.gitignore @@ -122,5 +122,5 @@ dist /playwright-report/ /blob-report/ /playwright/.cache/ - -playwright/.auth +/e2e/.cache/ +e2e/.auth diff --git a/src/frontend/e2e/01-create-new-project.spec.ts b/src/frontend/e2e/01-create-new-project.spec.ts index 2d72ad9e88..184875f308 100644 --- a/src/frontend/e2e/01-create-new-project.spec.ts +++ b/src/frontend/e2e/01-create-new-project.spec.ts @@ -3,18 +3,14 @@ import { test, expect } from '@playwright/test'; -import { tempLogin } from './helpers'; - test('create new project', async ({ browserName, page }) => { // Specific for this large test, only run in one browser // (playwright.config.ts is configured to run all browsers by default) test.skip(browserName !== 'chromium', 'Test only for chromium!'); - // 0. Temp Login - await tempLogin(page); - await page.getByRole('button', { name: '+ Create New Project' }).click(); - // 1. Project Details Step + await page.goto('/'); + await page.getByRole('button', { name: '+ Create New Project' }).click(); await page.getByRole('button', { name: 'NEXT' }).click(); await expect(page.getByText('Project Name is Required.')).toBeVisible(); await expect(page.getByText('Short Description is Required.', { exact: true })).toBeVisible(); diff --git a/src/frontend/e2e/02-mapper-flow.spec.ts b/src/frontend/e2e/02-mapper-flow.spec.ts index 942ff9d347..87f17e618f 100644 --- a/src/frontend/e2e/02-mapper-flow.spec.ts +++ b/src/frontend/e2e/02-mapper-flow.spec.ts @@ -3,7 +3,7 @@ import { test, expect } from '@playwright/test'; -import { tempLogin, openTestProject } from './helpers'; +import { openTestProject } from './helpers'; test.describe('mapper flow', () => { test('task actions', async ({ browserName, page }) => { @@ -11,11 +11,8 @@ test.describe('mapper flow', () => { // (playwright.config.ts is configured to run all browsers by default) test.skip(browserName !== 'chromium', 'Test only for chromium!'); - // 0. Temp Login - await tempLogin(page); - await openTestProject(page); - // 1. Click on task area on map + await openTestProject(page); await page.locator('canvas').click({ position: { x: 445, diff --git a/src/frontend/e2e/auth.setup.ts b/src/frontend/e2e/auth.setup.ts new file mode 100644 index 0000000000..1289cfa320 --- /dev/null +++ b/src/frontend/e2e/auth.setup.ts @@ -0,0 +1,25 @@ +import { test as setup, expect } from '@playwright/test'; +import path from 'path'; + +const authFile = path.join(__dirname, './.auth/user.json'); + +setup('authenticate', async ({ page }) => { + // Navigate to the app's base URL + await page.goto('/'); + await page.getByRole('button', { name: 'Sign in' }).click(); + + // Select OSM login + await page.getByText('Personal OSM Account').click(); + await page.waitForSelector('text=Log in to OpenStreetMap'); + + // OSM Login page + await page.getByLabel('Email Address or Username').fill(process.env.OSM_USERNAME || 'username'); + await page.getByLabel('Password').fill(process.env.OSM_PASSWORD || 'password'); + await page.getByRole('button', { name: 'Log in' }).click(); + + // Wait for redirect and valid login (sign out button) + await page.waitForSelector('text=Sign Out'); + + // Save authentication state + await page.context().storageState({ path: authFile }); +}); diff --git a/src/frontend/e2e/helpers.ts b/src/frontend/e2e/helpers.ts index 5c5a3d26da..54b9b92fe9 100644 --- a/src/frontend/e2e/helpers.ts +++ b/src/frontend/e2e/helpers.ts @@ -1,11 +1,5 @@ import { Page } from '@playwright/test'; -export async function tempLogin(page: Page) { - await page.goto('/'); - await page.getByRole('button', { name: 'Sign in' }).click(); - await page.getByText('Temporary Account').click(); -} - export async function openTestProject(page: Page) { // open project card with regex text 'Project Create Playwright xxx' await page diff --git a/src/frontend/playwright.config.ts b/src/frontend/playwright.config.ts index dfa5cf7cbf..4c4446bfe1 100644 --- a/src/frontend/playwright.config.ts +++ b/src/frontend/playwright.config.ts @@ -28,17 +28,31 @@ export default defineConfig({ /* Configure projects for major browsers */ projects: [ + // Setup project + { name: 'setup', testMatch: /.*\.setup\.ts/ }, { name: 'chromium', - use: { browserName: 'chromium' }, + use: { + browserName: 'chromium', + storageState: 'e2e/.auth/user.json', + }, + dependencies: ['setup'], }, { name: 'firefox', - use: { browserName: 'firefox' }, + use: { + browserName: 'firefox', + storageState: 'e2e/.auth/user.json', + }, + dependencies: ['setup'], }, { name: 'webkit', - use: { browserName: 'webkit' }, + use: { + browserName: 'webkit', + storageState: 'playwright/.auth/user.json', + }, + dependencies: ['setup'], }, /* Test against mobile viewports. */