Skip to content

End-to-End Tests With Playwright: Frontend, Backend and Database · Part 11 of 14 in the series

Part 11: Log In Once, Test Everywhere

Let a setup project log in a single time, save the cookie as storage state, and start every test that needs a member with it. The red tests turn green without a change, and the login gets tests of its own in all four sections.

Quest objectives

  • Understand what storage state is and why one saved login works for every worker
  • Put a member into the template database and keep it through the reset before each test
  • Log in once in a setup project and start other projects with the saved state
  • Run a block of tests as a visitor with test.use
  • Switch the mocked login of the frontend tests with an option fixture
  • Test the login where each question belongs: database, API, page and one whole flow

Half of the suite is red, and for an honest reason: the tests act like visitors, and visitors may no longer change the board. So the tests have to log in.

The obvious way is to fill in the login form at the start of every test. That works, but it costs time in each of them, and it tests the login form again and again where once is enough. Playwright has a better way: log in once, save what the browser knows afterwards, and start every other test with it.

One key, cut once and copied for every worker: a single login is enough for the whole run.
One key, cut once and copied for every worker: a single login is enough for the whole run.

What a browser knows after a login is, for this app, one cookie. Playwright calls the cookies of a browser, together with what pages have put into its local storage, the storage state. It can write that state into a file, and it can start a test with the state from a file, as if the login had happened a moment ago in this very browser.

So the plan is: a setup project, like the one that builds the template database, logs in once through the real form and saves the file. The projects that need a member start from it.

Why one login is enough for every worker

One thing about this plan deserves a second look. Since part 6 every worker runs its own server, on its own database and its own port. The login will happen on one of them. Why should all the others accept its cookie? Four things come together:

  1. The member exists in every database. You will put robin into the template, and the database of every worker is a copy of it. Robin even has the same id in all of them.

  2. All servers sign with the same secret. The fixture that starts the app hands the same secret to every copy, so a signature from one server is valid on all of them.

  3. The cookie holds only the member's id and the signature. Nothing is stored on the server that the other servers would be missing.

  4. Cookies belong to a host, not to a port. A cookie that localhost set on one port is sent to localhost on every other port too.

The first two are yours to set up in this part. The third is how the app was built in the last part, and the fourth is how browsers work.

A member in every database

Start with what several files need to know: who the member is, and where the saved state lies. A new file, tests/support/users.ts:

tests/support/users.ts
/** The member that every test database comes with. */
export const MEMBER = { name: 'robin', password: 'quest-master' };

/** Where the login setup saves the cookies of the logged-in member. */
export const MEMBER_STATE = 'playwright/.auth/member.json';

/** The opposite: a browser without any cookies. */
export const VISITOR_STATE = { cookies: [], origins: [] };

VISITOR_STATE is a storage state as well, written out by hand: no cookies and nothing else. It is for the tests that want to be a visitor.

The file behind MEMBER_STATE will hold a login. Add its folder to .gitignore:

.gitignore
node_modules
.env
web/dist
test-results
playwright-report
playwright/.auth

Now the template. In tests/setup/database.setup.ts, create the member after the migrations, with the app's own function:

tests/setup/database.setup.ts
import { test as setup } from '@playwright/test';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { connect } from '../../server/db/client.ts';
import { createUser } from '../../server/users.ts';
import { TEMPLATE, databaseUrl, onServer } from '../support/databases.ts';
import { MEMBER } from '../support/users.ts';

setup('build the template database', async () => {
  await onServer(
    `drop database if exists ${TEMPLATE} with (force)`,
    `create database ${TEMPLATE}`,
  );

  // The same migrations the app runs, from the first to the last.
  const { db, pool } = connect(databaseUrl(TEMPLATE));
  await migrate(db, { migrationsFolder: './drizzle' });

  // What every test may count on: one member who can log in.
  await createUser(db, MEMBER.name, MEMBER.password);
  await pool.end();
});

Two imports and the two lines before pool.end() are new. Because it is createUser from server/users.ts that does the work, the member of the tests is stored exactly as the app stores a member, salt and hash included.

Next, the fixtures in tests/fixtures.ts. MEMBER is imported at the top, and two places change:

tests/fixtures.ts
import { once } from 'node:events';
import type { AddressInfo } from 'node:net';
import { serve } from '@hono/node-server';
import { test as base } from '@playwright/test';
import { sql } from 'drizzle-orm';
import { createApp } from '../server/app.ts';
import { connect, type Db } from '../server/db/client.ts';
import { QuestBoard } from './support/board.ts';
import { TEMPLATE, databaseUrl, onServer } from './support/databases.ts';
import { MEMBER } from './support/users.ts';

type TestFixtures = {
  /** This worker's database, with empty tables. */
  db: Db;
  board: QuestBoard;
};

type WorkerFixtures = {
  workerDb: Db;
  /** The address of this worker's own API. */
  server: string;
};

export const test = base.extend<TestFixtures, WorkerFixtures>({
  // Once per worker: a database of its own, copied from the template.
  workerDb: [
    async ({}, use, workerInfo) => {
      const name = `questboard_test_${workerInfo.parallelIndex}`;
      await onServer(
        `drop database if exists ${name} with (force)`,
        `create database ${name} template ${TEMPLATE}`,
      );
      const { db, pool } = connect(databaseUrl(name));

      await use(db);

      await pool.end();
      await onServer(`drop database ${name}`);
    },
    { scope: 'worker' },
  ],

  // Once per worker: the app on a free port, working on this worker's database.
  server: [
    async ({ workerDb }, use) => {
      const app = createApp(workerDb, 'a secret only the tests know');
      const server = serve({ fetch: app.fetch, port: 0 });
      await once(server, 'listening');
      const { port } = server.address() as AddressInfo;

      await use(`http://localhost:${port}`);

      server.close();
    },
    { scope: 'worker' },
  ],

  // Requests and pages of a test go to its worker's server.
  baseURL: async ({ server }, use) => {
    await use(server);
  },

  // Before every test: back to what the template holds, so no test sees what another one
  // left behind. `auto` runs this for tests that never mention `db` as well.
  db: [
    async ({ workerDb }, use) => {
      await workerDb.execute(sql`truncate quests restart identity`);
      await workerDb.execute(sql`delete from users where name <> ${MEMBER.name}`);
      await use(workerDb);
    },
    { auto: true },
  ],

  board: async ({ page }, use) => {
    await use(new QuestBoard(page));
  },
});

export { expect } from '@playwright/test';

The server gets its secret. In the server fixture, createApp now gets its second argument, a fixed string. It is the same in every worker, which is point 2 of the list above, and it has nothing to do with the SESSION_SECRET in your .env. TypeScript is content again as well.

The reset keeps the member. Until now "before every test" meant: empty the table. With a member in the template it means: back to what the template holds. The quests are emptied as before. The new line deletes everyone from users except robin. A test may add members of its own, and the next test must not find them, but robin has to stay.

The login as a setup project

The login goes through the real form, so the page object from part 7 has to know that form. In tests/support/board.ts:

tests/support/board.ts
import type { Locator, Page } from '@playwright/test';

/** The quest board as a visitor sees it: where things are on the page, and how to use them. */
export class QuestBoard {
  readonly page: Page;
  readonly title: Locator;
  readonly reward: Locator;
  readonly addButton: Locator;
  readonly quests: Locator;
  readonly problem: Locator;
  readonly member: Locator;
  readonly loginButton: Locator;

  constructor(page: Page) {
    this.page = page;
    this.title = page.getByLabel('New quest');
    this.reward = page.getByPlaceholder('Reward');
    this.addButton = page.getByRole('button', { name: 'Add quest' });
    this.quests = page.getByRole('list', { name: 'Quests' }).getByRole('listitem');
    this.problem = page.getByRole('alert');
    this.member = page.getByText('Logged in as');
    this.loginButton = page.getByRole('button', { name: 'Log in' });
  }

  async open() {
    await this.page.goto('/');
  }

  async logIn(name: string, password: string) {
    await this.page.getByLabel('Name').fill(name);
    await this.page.getByLabel('Password').fill(password);
    await this.loginButton.click();
  }

  async add(title: string, reward?: number) {
    await this.title.fill(title);
    if (reward !== undefined) await this.reward.fill(String(reward));
    await this.addButton.click();
  }

  /** The checkbox that marks a quest as done. */
  checkbox(title: string) {
    return this.page.getByRole('checkbox', { name: title });
  }

  deleteButton(title: string) {
    return this.page.getByRole('button', { name: `Delete ${title}` });
  }
}

Two locators and one method are new. member finds the line "Logged in as …", loginButton the button of the login form, and logIn fills in name and password and clicks it.

Now the setup itself, a new file beside the one for the database, tests/setup/login.setup.ts:

tests/setup/login.setup.ts
import { expect, test as setup } from '../fixtures.ts';
import { MEMBER, MEMBER_STATE } from '../support/users.ts';

setup('log in as a member and save the session', async ({ board, page }) => {
  await board.open();
  await board.logIn(MEMBER.name, MEMBER.password);
  await expect(board.member).toHaveText(/Logged in as robin/);

  // The cookies of this browser, written to a file for the other projects to start with.
  await page.context().storageState({ path: MEMBER_STATE });
});

It imports test from tests/fixtures.ts and not from Playwright. So it gets what an end-to-end test gets: a database copied from the template, a server of its own on that database, and the board. It opens the page, logs in as robin and waits until the page says so. That assertion is not decoration. The click returns before the server has answered, and the cookie is there only after the answer.

The last line saves the state. The page of every test lives in a browser context: Playwright's word for a browser session that shares nothing with any other, with cookies and storage of its own. page.context() is the context this page belongs to, and storageState({ path }) writes its cookies into the file.

What is left is to tell Playwright when this runs and who starts with the result. playwright.config.ts:

playwright.config.ts
import { existsSync } from 'node:fs';
import { defineConfig, devices } from '@playwright/test';
import { MEMBER_STATE } from './tests/support/users.ts';

// The tests read the same settings as the app. Where there is no .env, such as in a
// pipeline, the variables are set from outside.
if (existsSync('.env')) process.loadEnvFile();

// The built frontend, served by `vite preview`.
const preview = 'http://localhost:4173';

export default defineConfig({
  fullyParallel: true,
  reporter: [['list'], ['html']],
  use: {
    // Record every test, and keep the recording of those that fail.
    trace: 'retain-on-failure',
    screenshot: 'only-on-failure',
  },
  projects: [
    {
      name: 'setup',
      testDir: './tests/setup',
      testMatch: 'database.setup.ts',
    },
    {
      name: 'login',
      testDir: './tests/setup',
      testMatch: 'login.setup.ts',
      dependencies: ['setup'],
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'database',
      testDir: './tests/database',
      dependencies: ['setup'],
    },
    {
      name: 'backend',
      testDir: './tests/backend',
      dependencies: ['login'],
      use: { storageState: MEMBER_STATE },
    },
    {
      name: 'frontend',
      testDir: './tests/frontend',
      use: { ...devices['Desktop Chrome'], baseURL: preview },
    },
    {
      name: 'e2e',
      testDir: './tests/e2e',
      dependencies: ['login'],
      use: { ...devices['Desktop Chrome'], storageState: MEMBER_STATE },
    },
  ],
  // Before the tests, Playwright builds the frontend and serves the result. The frontend
  // tests open it there; the servers of the workers hand out the same files from web/dist.
  webServer: {
    command: 'npm run build && npm run preview',
    url: preview,
    reuseExistingServer: false,
  },
});
  • setup used to take every file that ends in .setup.ts. There are two of them now, so it names its own: database.setup.ts.

  • login is a new project for login.setup.ts. It depends on setup, because it needs the template, and it gets a browser, because it fills in a form.

  • backend and e2e now depend on login. Dependencies form a chain: whoever asks for login gets setup before it. Both projects start with storageState: MEMBER_STATE, the path from tests/support/users.ts, imported at the top of the config. For e2e that means: the browser of every test starts with robin's cookie. The request fixture of the backend tests reads the same option and sends the cookie along with its requests, without any browser.

  • database stays as it is. Its tests call functions, and a function does not ask who is logged in.

  • frontend depends on nothing, as before. Its API is made up by the tests, so its login will be too.

The frontend section answers for itself

In the frontend section the page asks /api/me too, and so far the catch-all route aborts that request. The answer belongs in the page fixture, where it holds for every test. In tests/frontend/fixtures.ts, replace the block that begins with export const test with this one. The line that exports expect stays below it:

tests/frontend/fixtures.ts
type Fixtures = {
  board: QuestBoard;
  /** Whether the mocked API knows the visitor as a member. `test.use({ loggedIn: false })` turns it off. */
  loggedIn: boolean;
};

export const test = base.extend<Fixtures>({
  loggedIn: [true, { option: true }],

  page: async ({ page, loggedIn }, use) => {
    // A request to the API that a test has not mocked goes nowhere, and never to a real server.
    await page.route('**/api/**', (route) => route.abort());
    // Who is logged in is something every page asks, so it is answered for all tests.
    await mockApi(
      page,
      'GET',
      '/me',
      loggedIn ? { json: { name: 'robin' } } : { status: 401, json: { error: 'Not logged in.' } },
    );
    await use(page);
  },

  board: async ({ page }, use) => {
    await use(new QuestBoard(page));
  },
});

loggedIn is an option fixture: a fixture that is a plain value with a default, here true, marked with { option: true }. A test file or a describe block can choose another value with test.use({ loggedIn: false }).

The page fixture asks for that value and mocks GET /api/me to match: robin's name, or the 401 that the real API gives a visitor. The mock is set up after the catch-all, so it is the newer route and wins for this one request. A test that mocks /me itself is newer still and wins over this one.

The default is the member, because that is what the tests from before need. Run the suite now if you like: every test that was red in the last part passes again, and you have not touched a single one of them. The saved state and the mocked answer put them back where they were, in front of a board they are allowed to change.

New tests for the login

The old tests are green, but nothing tests the login itself yet. It gets one new file in each section, and each file asks the questions its section is there for.

The database first, in tests/database/users.spec.ts:

tests/database/users.spec.ts
import { users } from '../../server/db/schema.ts';
import { createUser, findUserByLogin } from '../../server/users.ts';
import { expect, test } from '../fixtures.ts';
import { MEMBER } from '../support/users.ts';

test('every test database comes with the member', async ({ db }) => {
  expect(await findUserByLogin(db, MEMBER.name, MEMBER.password)).toMatchObject({ id: 1, name: 'robin' });
  expect(await db.select().from(users)).toHaveLength(1);
});

test('stores a hash and never the password', async ({ db }) => {
  const kim = await createUser(db, 'kim', 'open-sesame');

  expect(kim.passwordHash).not.toContain('open-sesame');
  expect(await findUserByLogin(db, 'kim', 'open-sesame')).toEqual(kim);
});

test('gives two members with the same password different hashes', async ({ db }) => {
  const kim = await createUser(db, 'kim', 'open-sesame');
  const alex = await createUser(db, 'alex', 'open-sesame');

  expect(kim.passwordHash).not.toBe(alex.passwordHash);
});

test('finds nobody for a wrong password or an unknown name', async ({ db }) => {
  expect(await findUserByLogin(db, MEMBER.name, 'quest-mister')).toBeUndefined();
  expect(await findUserByLogin(db, 'nobody', MEMBER.password)).toBeUndefined();
});

test('rejects a name that is taken', async ({ db }) => {
  await expect(createUser(db, MEMBER.name, 'another-password')).rejects.toMatchObject({
    cause: { constraint: 'users_name_unique' },
  });
});

The first test checks what the setup promises: every test database has robin, with the id 1, and nobody else, whatever the test before it did. The next two are about what is stored: the hash does not contain the password, and two members with the same password get different hashes, which is the salt at work. The last test uses the pattern from part 5: the unique constraint of the database, named in cause, turns a second robin down.

One layer up, tests/backend/login.spec.ts:

tests/backend/login.spec.ts
import { quests } from '../../server/db/schema.ts';
import { expect, test } from '../fixtures.ts';
import { seedQuests } from '../support/seed.ts';
import { MEMBER, VISITOR_STATE } from '../support/users.ts';

test.describe('a member', () => {
  test('is known to the API', async ({ request }) => {
    const response = await request.get('/api/me');

    expect(response.status()).toBe(200);
    expect(await response.json()).toEqual({ name: 'robin' });
  });

  test('is forgotten after logging out', async ({ request }) => {
    const response = await request.post('/api/logout');

    expect(response.status()).toBe(204);
    expect((await request.get('/api/me')).status()).toBe(401);
  });
});

test.describe('a visitor', () => {
  // These tests start without the saved cookies.
  test.use({ storageState: VISITOR_STATE });

  test('is not known to the API', async ({ request }) => {
    const response = await request.get('/api/me');

    expect(response.status()).toBe(401);
    expect(await response.json()).toEqual({ error: 'Not logged in.' });
  });

  test('may read the board', async ({ request, db }) => {
    await seedQuests(db, { title: 'Find the lost sword' });

    const response = await request.get('/api/quests');

    expect(response.status()).toBe(200);
    expect(await response.json()).toHaveLength(1);
  });

  test('may not change the board', async ({ request, db }) => {
    const [sword] = await seedQuests(db, { title: 'Find the lost sword' });

    const answers = [
      await request.post('/api/quests', { data: { title: 'Map the cave' } }),
      await request.patch(`/api/quests/${sword.id}`, { data: { done: true } }),
      await request.delete(`/api/quests/${sword.id}`),
    ];

    expect(answers.map((response) => response.status())).toEqual([401, 401, 401]);
    expect(await answers[0].json()).toEqual({ error: 'Log in to change the board.' });
    expect(await db.select().from(quests)).toEqual([sword]);
  });

  test('becomes a member with the right password', async ({ request }) => {
    const response = await request.post('/api/login', { data: MEMBER });

    expect(response.status()).toBe(200);
    expect(await response.json()).toEqual({ name: 'robin' });
    // The cookie cannot be read by scripts on the page, and other sites cannot send it along.
    const { cookies } = await request.storageState();
    expect(cookies).toMatchObject([{ name: 'session', httpOnly: true, sameSite: 'Lax' }]);
    expect((await request.get('/api/me')).status()).toBe(200);
  });

  test('stays a visitor with a wrong password', async ({ request }) => {
    const response = await request.post('/api/login', {
      data: { name: MEMBER.name, password: 'quest-mister' },
    });

    expect(response.status()).toBe(401);
    expect(await response.json()).toEqual({ error: 'Wrong name or password.' });
    expect((await request.storageState()).cookies).toEqual([]);
  });

  test('cannot make up a cookie', async ({ request }) => {
    // The id of the member, but without the signature only the server can make.
    const response = await request.get('/api/me', { headers: { Cookie: 'session=1' } });

    expect(response.status()).toBe(401);
  });
});

Member and visitor. The first describe block runs the way the project is configured, with robin's cookie. The second begins with test.use({ storageState: VISITOR_STATE }). Inside that block the option from the config is replaced, and its tests start without a cookie. test.use applies to a whole file or to a describe block, not to a single test.

What a visitor may do. Read the board: yes. Change it: no. The test sends all three changing requests, expects 401 three times, and then looks into the database, where the one quest lies exactly as it was put there. As in part 6, the answer is one thing and the stored row another.

Logging in. request keeps cookies from one request to the next, as a browser does. After POST /api/login, request.storageState() shows what it holds: a cookie named session that is httpOnly and sameSite: 'Lax'. The GET /api/me after it answers 200. A wrong password leaves it without any cookie. The last test tries a shortcut and sends session=1, the id of robin without a signature. The answer is 401: this is what the signature is for.

Logging out is in the first block. After POST /api/logout the same request is a visitor. No other test is disturbed by that, although all of them use the same saved cookie. Every test gets its own copy of the state from the file, and logging out makes only this copy forget the cookie. The file stays as it is.

The frontend section, tests/frontend/login.spec.ts:

tests/frontend/login.spec.ts
import { DRAGON, SWORD, expect, mockApi, test } from './fixtures.ts';

test.describe('a visitor', () => {
  test.use({ loggedIn: false });

  test('can read the board but finds nothing to change it with', async ({ page, board }) => {
    await mockApi(page, 'GET', '/quests', { json: [SWORD, DRAGON] });

    await board.open();

    await expect(board.quests).toHaveCount(2);
    await expect(board.loginButton).toBeVisible();
    await expect(board.addButton).toBeHidden();
    await expect(board.checkbox('Find the lost sword')).toBeDisabled();
    await expect(board.deleteButton('Find the lost sword')).toBeHidden();
  });

  test('logs in and gets the form for new quests', async ({ page, board }) => {
    await mockApi(page, 'GET', '/quests', { json: [SWORD] });
    await mockApi(page, 'POST', '/login', { json: { name: 'robin' } });
    await board.open();

    const request = page.waitForRequest((request) => request.method() === 'POST');
    await board.logIn('robin', 'quest-master');

    expect((await request).postDataJSON()).toEqual({ name: 'robin', password: 'quest-master' });
    await expect(board.member).toBeVisible();
    await expect(board.addButton).toBeVisible();
    await expect(board.checkbox('Find the lost sword')).toBeEnabled();
    await expect(board.loginButton).toBeHidden();
  });

  test('is told when name or password are wrong', async ({ page, board }) => {
    await mockApi(page, 'GET', '/quests', { json: [] });
    await mockApi(page, 'POST', '/login', { status: 401, json: { error: 'Wrong name or password.' } });
    await board.open();

    await board.logIn('robin', 'quest-mister');

    await expect(board.problem).toHaveText('Wrong name or password.');
    await expect(board.loginButton).toBeVisible();
  });
});

test('a member can log out', async ({ page, board }) => {
  await mockApi(page, 'GET', '/quests', { json: [SWORD] });
  await mockApi(page, 'POST', '/logout', { status: 204 });
  await board.open();

  await page.getByRole('button', { name: 'Log out' }).click();

  await expect(board.loginButton).toBeVisible();
  await expect(board.member).toBeHidden();
  await expect(board.addButton).toBeHidden();
});

The block for the visitor switches the option off with test.use({ loggedIn: false }). Its first test is the page's side of "may not change": the list is there, but the form for new quests and the delete button are hidden and the checkbox is disabled. toBeHidden() also passes when an element does not exist at all, which is the case here.

The second test mocks POST /login, checks with waitForRequest what the page sent, as in part 7, and then that the page changes to the member's view. The third lets the mocked API say no. The last test stands outside the block, so it starts as a member, and logs out.

And one flow through everything, tests/e2e/login.spec.ts:

tests/e2e/login.spec.ts
import { quests } from '../../server/db/schema.ts';
import { expect, test } from '../fixtures.ts';
import { seedQuests } from '../support/seed.ts';
import { MEMBER, VISITOR_STATE } from '../support/users.ts';

test.describe('a visitor', () => {
  test.use({ storageState: VISITOR_STATE });

  test('logs in, adds a quest and logs out again', async ({ board, db, page }) => {
    await seedQuests(db, { title: 'Find the lost sword' });
    await board.open();
    await expect(board.addButton).toBeHidden();

    await board.logIn(MEMBER.name, MEMBER.password);
    await board.add('Map the cave', 25);

    await expect(board.quests).toHaveText([/Find the lost sword/, /Map the cave.*25 gold/]);
    expect(await db.select().from(quests)).toHaveLength(2);

    await page.getByRole('button', { name: 'Log out' }).click();

    await expect(board.loginButton).toBeVisible();
    await expect(board.checkbox('Map the cave')).toBeDisabled();
  });

  test('stays outside with a wrong password', async ({ board }) => {
    await board.open();

    await board.logIn(MEMBER.name, 'quest-mister');

    await expect(board.problem).toHaveText('Wrong name or password.');
    await expect(board.member).toBeHidden();
  });
});

test('a member is still logged in after a reload', async ({ board, page }) => {
  await board.open();
  await expect(board.member).toHaveText(/Logged in as robin/);

  await page.reload();

  await expect(board.member).toHaveText(/Logged in as robin/);
  await expect(board.addButton).toBeVisible();
});

The first test starts as a visitor and finds no form for new quests. It logs in through the real form, with the real check of the password behind it, adds a quest that the page shows and the database holds, and logs out, after which the checkbox is disabled again. Apart from the setup, the tests of this file are the only place in the suite where a login goes through the form and the real API.

The last test stands outside the block and starts with the saved state. It never logs in, and the page greets it by name, before and after a reload. That is storage state seen from the browser.

Run everything:

questboard
$ npx playwright test --reporter=dotRunning 73 tests using 8 workers······································[✓] Pulling schema from database...···································  73 passed (8.0s)

73 passed in 8 seconds: the 52 from before, the login setup and 20 new tests. Compare that with the last part, where the same eight workers needed more than a minute to tell you what was wrong.

The order of things shows best when you run one section with the list reporter:

questboard
$ npm run test:e2e> questboard@1.0.0 test:e2e> playwright test --project=e2eRunning 10 tests using 8 workers  ✓   1 [setup] › tests/setup/database.setup.ts:8:1 › build the template database (156ms)  ✓   2 [login] › tests/setup/login.setup.ts:4:1 › log in as a member and save the session (281ms)  ✓   9 [e2e] › tests/e2e/quest-board.spec.ts:16:1 › the board shows what is in the database (402ms)  ✓   6 [e2e] › tests/e2e/login.spec.ts:36:1 › a member is still logged in after a reload (461ms)  ✓   4 [e2e] › tests/e2e/login.spec.ts:26:3 › a visitor › stays outside with a wrong password (566ms)  ✓   5 [e2e] › tests/e2e/quest-board.spec.ts:30:1 › a finished quest is still finished after a reload (549ms)  ✓   7 [e2e] › tests/e2e/quest-board.spec.ts:43:1 › a deleted quest is gone for good (561ms)  ✓  10 [e2e] › tests/e2e/quest-board.spec.ts:55:1 › a title that is taken is turned down, all the way from the database (503ms)  ✓   8 [e2e] › tests/e2e/quest-board.spec.ts:5:1 › a new quest travels from the form into the database (527ms)  ✓   3 [e2e] › tests/e2e/login.spec.ts:9:3 › a visitor › logs in, adds a quest and logs out again (805ms)  10 passed (5.0s)

Look at the first two lines. setup builds the template, login logs in and saves the session, and only then do the eight end-to-end tests start, spread over the workers. You asked for the project e2e only. Playwright ran what it depends on first, and the login cost about a third of a second, once.

What you have now

One login per run, saved as storage state. Every backend and end-to-end test starts as a member, a test.use turns a block of them into visitors, and the frontend tests choose with an option who they are. The suite is green again with 73 tests, and the login is tested where each question belongs: the hashes in the database, the 401s and the cookie in the API, the two views in the page, and one whole flow through the form.

The next two parts add checks that ride on the frontend section. In the next part it is accessibility: a rule engine called axe looks at the page in several of its states, and you will see what it finds and what it cannot find. After that comes how the page looks.

Comments

The comments are GitHub Discussions: sign in with GitHub to write one.

The comments come from GitHub, through giscus. Loading them sends your IP address to giscus.app and GitHub.