new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · all subjects

fixtures

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Use before and after hooks for setup and isolation

Use test.beforeEach() and test.afterEach() hooks to run setup code before each test without breaking test isolation. This keeps tests independent while avoiding repetition. It is acceptable to have some duplication in simple tests if it keeps them clearer and easier to maintain.

beforeEach hook example with login

import { test } from '@playwright/test'; test.beforeEach(async ({ page }) => { await page.goto('https://github.com/login'); await page.getByLabel('Username or email address').fill('username'); await page.getByLabel('Password').fill('password'); await page.getByRole('button', { name: 'Sign in' }).click(); }); test('first', async ({ page }) => { // page is signed in. }); test('second', async ({ page }) => { // page is signed in. });

Reuse signed-in state with setup project

You can reuse signed-in state across tests using a setup project. This allows logging in only once and then skipping the login step for all subsequent tests.

Use custom options in tests

Custom options defined in extended test are available as parameters in test functions, just like built-in fixtures. Access them by including them in the destructured parameters.

Use custom options in fixtures

Custom options can be used within fixture definitions. For example, you can override the default page fixture to use a custom option parameter to configure the page setup before tests run.

Custom fixture with option example

Example of overriding the page fixture with a custom option in my-test.ts: export const test = base.extend<TestOptions>({ person: ['John', { option: true }], page: async ({ page, person }, use) => { await page.goto('/chat'); await page.getByLabel('User Name').fill(person); await page.getByText('Enter chat room').click(); await use(page); }, });

First test example with page fixture

import { test, expect } from '@playwright/test'; test('has title', async ({ page }) => { await page.goto('https://playwright.dev/'); // Expect a title "to contain" a substring. await expect(page).toHaveTitle(/Playwright/); }); test('get started link', async ({ page }) => { await page.goto('https://playwright.dev/'); // Click the get started link. await page.getByRole('link', { name: 'Get started' }).click(); // Expects page to have a heading with the name of Installation. await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); });

Give your agent this brain