test(e2e): allow testing of multiple users (#54752)

This commit is contained in:
Oliver Eyton-Williams
2024-05-13 17:33:36 +02:00
committed by GitHub
parent 372bb9f38a
commit 86860e85a5
2 changed files with 41 additions and 6 deletions

View File

@@ -1,9 +1,31 @@
import { execSync } from 'child_process';
import { test as setup } from '@playwright/test';
setup('Login', async ({ page }) => {
await page.goto('/');
await page.getByRole('link', { name: 'Sign in' }).click();
await page
.context()
.storageState({ path: 'playwright/.auth/certified-user.json' });
setup.describe('certifieduser', () => {
setup('can sign in', async ({ request }) => {
await request.get(process.env.API_LOCATION + '/signin');
await request.storageState({
path: 'playwright/.auth/certified-user.json'
});
});
});
setup.describe('developmentuser', () => {
// We can only sign in as a single user (one with email: 'foo@bar.com'), so
// changing users means changing the record with that email in the database.
setup.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user');
});
setup.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
});
setup('can sign in', async ({ request }) => {
await request.get(process.env.API_LOCATION + '/signin');
await request.storageState({
path: 'playwright/.auth/development-user.json'
});
});
});

13
e2e/signin.spec.ts Normal file
View File

@@ -0,0 +1,13 @@
import { test, expect } from '@playwright/test';
test.describe('signing in', () => {
test('welcomes the user', async ({ page }) => {
const welcomeText = 'Welcome back, Full Stack User.';
await page.goto('/');
await expect(page.getByText(welcomeText)).not.toBeVisible();
await page.getByRole('link', { name: 'Sign in' }).click();
await expect(page.getByText(welcomeText)).toBeVisible();
});
});