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

authentication/multiple-roles

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

Multiple signed-in roles with separate storage state files

Create multiple setup tests to authenticate as different roles, saving each to a separate file (e.g., `playwright/.auth/admin.json` and `playwright/.auth/user.json`). In test files, use `test.use({ storageState: 'playwright/.auth/admin.json' })` at the file or test.describe level to apply the appropriate role's state to specific tests.

Testing multiple roles together in one test

Example testing two authenticated roles in a single test: ```js import { test } from '@playwright/test'; test('admin and user', async ({ browser }) => { const adminContext = await browser.newContext({ storageState: 'playwright/.auth/admin.json' }); const adminPage = await adminContext.newPage(); const userContext = await browser.newContext({ storageState: 'playwright/.auth/user.json' }); const userPage = await userContext.newPage(); // ... interact with both adminPage and userPage ... await adminContext.close(); await userContext.close(); }); ``` Create separate contexts with different storage states to test interactions between multiple roles.

POM fixtures for multiple authenticated roles

Example creating fixtures for Page Object Models with multiple authenticated roles: ```js import { test as base, type Page, type Locator } from '@playwright/test'; class AdminPage { page: Page; greeting: Locator; constructor(page: Page) { this.page = page; this.greeting = page.locator('#greeting'); } } class UserPage { page: Page; greeting: Locator; constructor(page: Page) { this.page = page; this.greeting = page.locator('#greeting'); } } type MyFixtures = { adminPage: AdminPage; userPage: UserPage; }; export * from '@playwright/test'; export const test = base.extend<MyFixtures>({ adminPage: async ({ browser }, use) => { const context = await browser.newContext({ storageState: 'playwright/.auth/admin.json' }); const adminPage = new AdminPage(await context.newPage()); await use(adminPage); await context.close(); }, userPage: async ({ browser }, use) => { const context = await browser.newContext({ storageState: 'playwright/.auth/user.json' }); const userPage = new UserPage(await context.newPage()); await use(userPage); await context.close(); }, }); ``` In tests: `test('admin and user', async ({ adminPage, userPage }) => { ... })`

Give your agent this brain