Skip to content

Commit

Permalink
test: wip persist osm login across playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Nov 22, 2024
1 parent e424693 commit 8cb79db
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ dist
/playwright-report/
/blob-report/
/playwright/.cache/

playwright/.auth
/e2e/.cache/
e2e/.auth
8 changes: 2 additions & 6 deletions src/frontend/e2e/01-create-new-project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions src/frontend/e2e/02-mapper-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@

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 }) => {
// 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 openTestProject(page);

// 1. Click on task area on map
await openTestProject(page);
await page.locator('canvas').click({
position: {
x: 445,
Expand Down
25 changes: 25 additions & 0 deletions src/frontend/e2e/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -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 });
});
6 changes: 0 additions & 6 deletions src/frontend/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 17 additions & 3 deletions src/frontend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 8cb79db

Please sign in to comment.