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/api

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

API-based authentication in setup project

Example using API request for authentication: ```js import { test as setup } from '@playwright/test'; const authFile = 'playwright/.auth/user.json'; setup('authenticate', async ({ request }) => { await request.post('https://github.com/login', { form: { 'user': 'user', 'password': 'password' } }); await request.storageState({ path: authFile }); }); ``` This approach is faster than UI interaction when the web application supports API authentication.

API-based authentication in worker fixture

Example using API request for worker-scoped authentication: ```js import { test as baseTest, request } from '@playwright/test'; import fs from 'fs'; import path from 'path'; export * from '@playwright/test'; export const test = baseTest.extend<{}, { workerStorageState: string }>({ storageState: ({ workerStorageState }, use) => use(workerStorageState), workerStorageState: [async ({}, use) => { const id = test.info().parallelIndex; const fileName = path.resolve(test.info().project.outputDir, `.auth/${id}.json`); if (fs.existsSync(fileName)) { await use(fileName); return; } const context = await request.newContext({ storageState: undefined }); const account = await acquireAccount(id); await context.post('https://github.com/login', { form: { 'user': 'user', 'password': 'password' } }); await context.storageState({ path: fileName }); await context.dispose(); await use(fileName); }, { scope: 'worker' }], }); ``` Use `request.newContext()` instead of `browser.newPage()` for API-only authentication.

Give your agent this brain