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 · Test runner API · all subjects

test

77 notes in this subject, read out of this brain and free to use. This is page 2 of 2.

test.info() attachment example

import { test, expect } from '@playwright/test'; test('example test', async ({ page }) => { // ... await test.info().attach('screenshot', { body: await page.screenshot(), contentType: 'image/png', }); });

test.only() example

test.only('focus this test', async ({ page }) => { // Run only focused tests in the entire project. });

test.setTimeout() in beforeEach hook

test.beforeEach(async ({ page }, testInfo) => { // Extend timeout for all tests running this hook by 30 seconds. test.setTimeout(testInfo.timeout + 30000); });

test.setTimeout() in beforeAll hook

test.beforeAll(async () => { // Set timeout for this hook. test.setTimeout(60000); });

test.skip() at declaration example

import { test, expect } from '@playwright/test'; test.skip('never run', async ({ page }) => { // ... });

test.skip() with condition example

import { test, expect } from '@playwright/test'; test('Safari-only test', async ({ page, browserName }) => { test.skip(browserName !== 'webkit', 'This feature is Safari-only'); // ... });

test.skip() with callback example

import { test, expect } from '@playwright/test'; test.skip(({ browserName }) => browserName !== 'webkit', 'Safari-only'); test('Safari-only test 1', async ({ page }) => { // ... }); test('Safari-only test 2', async ({ page }) => { // ... });

test.slow() basic example

import { test, expect } from '@playwright/test'; test('slow test', async ({ page }) => { test.slow(); // ... });

test.slow() with callback example

import { test, expect } from '@playwright/test'; test.slow(({ browserName }) => browserName === 'webkit', 'all tests are slow in Safari'); test('slow in Safari 1', async ({ page }) => { // ... }); test('fail in Safari 2', async ({ page }) => { // ... });

test.step() basic example

import { test, expect } from '@playwright/test'; test('test', async ({ page }) => { await test.step('Log in', async () => { // ... }); await test.step('Outer step', async () => { // ... await test.step('Inner step', async () => { // ... }); }); });

test.step() with return value example

import { test, expect } from '@playwright/test'; test('test', async ({ page }) => { const user = await test.step('Log in', async () => { // ... return 'john'; }); expect(user).toBe('john'); });

test.step() TypeScript decorator example

function step(target: Function, context: ClassMethodDecoratorContext) { return function replacementMethod(...args: any) { const name = this.constructor.name + '.' + (context.name as string); return test.step(name, async () => { return await target.call(this, ...args); }, { box: true }); }; } class LoginPage { constructor(readonly page: Page) {} @step async login() { const account = { username: 'Alice', password: 's3cr3t' }; await this.page.getByLabel('Username or email address').fill(account.username); await this.page.getByLabel('Password').fill(account.password); await this.page.getByRole('button', { name: 'Sign in' }).click(); await expect(this.page.getByRole('button', { name: 'View profile and more' })).toBeVisible(); } } test('example', async ({ page }) => { const loginPage = new LoginPage(page); await loginPage.login(); });

test.step() with box option example

async function login(page) { await test.step('login', async () => { const account = { username: 'Alice', password: 's3cr3t' }; await page.getByLabel('Username or email address').fill(account.username); await page.getByLabel('Password').fill(account.password); await page.getByRole('button', { name: 'Sign in' }).click(); await expect(page.getByRole('button', { name: 'View profile and more' })).toBeVisible(); }, { box: true }); } test('example', async ({ page }) => { await page.goto('https://github.com/login'); await login(page); });

test.step() boxed decorator example

function boxedStep(target: Function, context: ClassMethodDecoratorContext) { return function replacementMethod(...args: any) { const name = this.constructor.name + '.' + (context.name as string); return test.step(name, async () => { return await target.call(this, ...args); }, { box: true }); }; } class LoginPage { constructor(readonly page: Page) {} @boxedStep async login() { // .... } } test('example', async ({ page }) => { const loginPage = new LoginPage(page); await loginPage.login(); });

test.step.skip() example

import { test, expect } from '@playwright/test'; test('my test', async ({ page }) => { // ... await test.step.skip('not yet ready', async () => { // ... }); });

test.use() basic example

import { test, expect } from '@playwright/test'; test.use({ locale: 'en-US' }); test('test with locale', async ({ page }) => { // Default context and page have locale as specified });

test.use() with fixture override example

import { test, expect } from '@playwright/test'; test.use({ locale: async ({}, use) => { // Read locale from some configuration file. const locale = await fs.promises.readFile('test-locale', 'utf-8'); await use(locale); }, }); test('test with locale', async ({ page }) => { // Default context and page have locale as specified });

Give your agent this brain