new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Playwright · API reference · all subjects

browser automation setup

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

PageTest class provides Page instance

When inheriting from PageTest instead of PlaywrightTest, Playwright automatically launches a browser, context, and page for you. PlaywrightTest only provides a Playwright instance and requires manual browser/context/page setup.

Playwright.create() static method

Playwright.create() is a static factory method that creates a new Playwright instance for accessing browser automation and API testing functionality.

Playwright.close() method

Playwright.close() closes the Playwright instance and releases all its resources.

Context option inheritance from use section

While a test or hook runs, every browser context created through the Playwright instance used by the test runner inherits context options from the use section. This includes contexts created with the built-in browser fixture, a separately launched browser, BrowserType.launchPersistentContext(), or a direct playwright-core import that resolves to the same instance. Explicit context options take precedence over inherited options.

Configuration scopes for test options

Playwright test options can be configured globally, per project, or per test. Global configuration is set in the use option of the Playwright config. Project-level configuration is set using the project option in the config. Test-level configuration is set using test.use() in the test file.

test.use() for overriding options in test files

Use test.use() in a test file to override use section options for specific tests or test suites. This can be called at the top level of a test file or inside a describe block to apply options to all tests in that scope.

Resetting options to config defaults

To reset an option to the value defined in the config file, pass undefined to test.use(). For example, test.use({ baseURL: undefined }) resets baseURL to its configured value. To completely unset a value, use long-form fixture notation: test.use({ baseURL: [async ({}, use) => use(undefined), { scope: 'test' }] }).

Example: Browser context inherits use options

Example showing that context created through browser.newContext() inherits use options from playwright.config.ts: test('should inherit use options on context when using built-in browser fixture', async ({ browser }) => { const context = await browser.newContext(); const page = await context.newPage(); expect(await page.evaluate(() => navigator.userAgent)).toBe('some custom ua'); expect(await page.evaluate(() => window.innerWidth)).toBe(100); await context.close(); }); When userAgent is 'some custom ua' and viewport { width: 100, height: 100 } are set in use section of config.

Give your agent this brain