docs: drop duplicate JS code snippets from test-api (#21466)

https://github.com/microsoft/playwright/issues/21385
This commit is contained in:
Max Schmitt 2023-03-16 19:01:15 +01:00 committed by GitHub
parent 1ffe01b027
commit 3ceac4bf53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 126 additions and 1285 deletions

View File

@ -1622,7 +1622,7 @@ This option configures a template controlling location of snapshots generated by
**Usage**
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -1632,18 +1632,6 @@ export default defineConfig({
});
```
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
testDir: './tests',
snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
});
```
**Details**
The value might include some "tokens" that will be replaced with actual values during test execution.
@ -1659,7 +1647,7 @@ tests/
And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:
```js tab=js-ts
```js
// page-click.spec.ts
import { test, expect } from '@playwright/test';
@ -1670,17 +1658,6 @@ test.describe('suite', () => {
});
```
```js tab=js-js
// page-click.spec.js
const { test, expect } = require('@playwright/test');
test.describe('suite', () => {
test('test should work', async ({ page }) => {
await expect(page).toHaveScreenshot(['foo', 'bar', 'baz.png']);
});
});
```
The list of supported tokens:
* `{testDir}` - Project's [`property: TestConfig.testDir`].
@ -1707,7 +1684,7 @@ Each token can be preceded with a single character that will be used **only if**
Consider the following config:
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -1721,22 +1698,6 @@ export default defineConfig({
});
```
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
snapshotPathTemplate: '__screenshots__{/projectName}/{testFilePath}/{arg}{ext}',
testMatch: 'example.spec.ts',
projects: [
{ use: { browserName: 'firefox' } },
{ name: 'chromium', use: { browserName: 'chromium' } },
],
});
```
In this config:
1. First project **does not** have a name, so its snapshots will be stored in `<configDir>/__screenshots__/example.spec.ts/...`.
1. Second project **does** have a name, so its snapshots will be stored in `<configDir>/__screenshots__/chromium/example.spec.ts/..`.

View File

@ -6,15 +6,7 @@ Playwright Test is based on the concept of the [test fixtures](../test-fixtures.
Playwright Test looks at each test declaration, analyses the set of fixtures the test needs and prepares those fixtures specifically for the test. Values prepared by the fixtures are merged into a single object that is available to the `test`, hooks, annotations and other fixtures as a first parameter.
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
@ -36,14 +28,7 @@ Learn how to [configure browser](../test-configuration.md) and see [available op
**Usage**
```js tab=js-js
test.beforeAll(async ({ browser }) => {
const page = await browser.newPage();
// ...
});
```
```js tab=js-ts
```js
test.beforeAll(async ({ browser }) => {
const page = await browser.newPage();
// ...
@ -58,14 +43,7 @@ Name of the browser that runs tests. Defaults to `'chromium'`. Useful to [annota
**Usage**
```js tab=js-js
test('skip this test in Firefox', async ({ page, browserName }) => {
test.skip(browserName === 'firefox', 'Still working on it');
// ...
});
```
```js tab=js-ts
```js
test('skip this test in Firefox', async ({ page, browserName }) => {
test.skip(browserName === 'firefox', 'Still working on it');
// ...
@ -84,14 +62,7 @@ Default [`property: Fixtures.page`] belongs to this context.
**Usage**
```js tab=js-js
test('example test', async ({ page, context }) => {
await context.route('*external.com/*', route => route.abort());
// ...
});
```
```js tab=js-ts
```js
test('example test', async ({ page, context }) => {
await context.route('*external.com/*', route => route.abort());
// ...
@ -108,19 +79,7 @@ This is the most common fixture used in a test.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
await page.goto('/signin');
await page.getByLabel('User Name').fill('user');
await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
@ -140,20 +99,7 @@ Isolated [APIRequestContext] instance for each test.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ request }) => {
await request.post('/signin', {
data: {
username: 'user',
password: 'password'
}
});
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('basic test', async ({ request }) => {

View File

@ -4,17 +4,7 @@
Playwright Test provides a `test` function to declare tests and `expect` function to write assertions.
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
await page.goto('https://playwright.dev/');
const name = await page.innerText('.navbar__title');
expect(name).toBe('Playwright');
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
@ -31,16 +21,7 @@ Declares a test.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
await page.goto('https://playwright.dev/');
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
@ -76,14 +57,7 @@ Note that worker process is restarted on test failures, and `afterAll` hook runs
**Usage**
```js tab=js-js
test.afterAll(async () => {
console.log('Done with tests');
// ...
});
```
```js tab=js-ts
```js
test.afterAll(async () => {
console.log('Done with tests');
// ...
@ -111,23 +85,7 @@ You can access all the same [Fixtures] as the test function itself, and also the
**Usage**
```js tab=js-js
// example.spec.js
const { test, expect } = require('@playwright/test');
test.afterEach(async ({ page }, testInfo) => {
console.log(`Finished ${testInfo.title} with status ${testInfo.status}`);
if (testInfo.status !== testInfo.expectedStatus)
console.log(`Did not run as expected, ended up at ${page.url()}`);
});
test('my test', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
// example.spec.ts
import { test, expect } from '@playwright/test';
@ -165,24 +123,7 @@ You can use [`method: Test.afterAll`] to teardown any resources set up in `befor
**Usage**
```js tab=js-js
// example.spec.js
const { test, expect } = require('@playwright/test');
test.beforeAll(async () => {
console.log('Before tests');
});
test.afterAll(async () => {
console.log('After tests');
});
test('my test', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
// example.spec.ts
import { test, expect } from '@playwright/test';
@ -222,21 +163,7 @@ You can use [`method: Test.afterEach`] to teardown any resources set up in `befo
**Usage**
```js tab=js-js
// example.spec.js
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({ page }, testInfo) => {
console.log(`Running ${testInfo.title}`);
await page.goto('https://my.start.url/');
});
test('my test', async ({ page }) => {
expect(page.url()).toBe('https://my.start.url/');
});
```
```js tab=js-ts
```js
// example.spec.ts
import { test, expect } from '@playwright/test';
@ -266,19 +193,7 @@ Declares a group of tests.
**Usage**
```js tab=js-js
test.describe('two tests', () => {
test('one', async ({ page }) => {
// ...
});
test('two', async ({ page }) => {
// ...
});
});
```
```js tab=js-ts
```js
test.describe('two tests', () => {
test('one', async ({ page }) => {
// ...
@ -310,21 +225,7 @@ Declares an anonymous group of tests. This is convenient to give a group of test
**Usage**
```js tab=js-js
test.describe(() => {
test.use({ colorScheme: 'dark' });
test('one', async ({ page }) => {
// ...
});
test('two', async ({ page }) => {
// ...
});
});
```
```js tab=js-ts
```js
test.describe(() => {
test.use({ colorScheme: 'dark' });
@ -412,15 +313,7 @@ Declares a test group similarly to [`method: Test.describe#1`]. Tests in this gr
**Usage**
```js tab=js-js
test.describe.fixme('broken tests', () => {
test('example', async ({ page }) => {
// This test will not run
});
});
```
```js tab=js-ts
```js
test.describe.fixme('broken tests', () => {
test('example', async ({ page }) => {
// This test will not run
@ -449,18 +342,7 @@ Declares a focused group of tests. If there are some focused tests or suites, al
**Usage**
```js tab=js-js
test.describe.only('focused group', () => {
test('in the focused group', async ({ page }) => {
// This test will run
});
});
test('not in the focused group', async ({ page }) => {
// This test will not run
});
```
```js tab=js-ts
```js
test.describe.only('focused group', () => {
test('in the focused group', async ({ page }) => {
// This test will run
@ -493,14 +375,7 @@ Declares a group of tests that could be run in parallel. By default, tests in a
**Usage**
```js tab=js-js
test.describe.parallel('group', () => {
test('runs in parallel 1', async ({ page }) => {});
test('runs in parallel 2', async ({ page }) => {});
});
```
```js tab=js-ts
```js
test.describe.parallel('group', () => {
test('runs in parallel 1', async ({ page }) => {});
test('runs in parallel 2', async ({ page }) => {});
@ -531,14 +406,7 @@ Declares a focused group of tests that could be run in parallel. This is similar
**Usage**
```js tab=js-js
test.describe.parallel.only('group', () => {
test('runs in parallel 1', async ({ page }) => {});
test('runs in parallel 2', async ({ page }) => {});
});
```
```js tab=js-ts
```js
test.describe.parallel.only('group', () => {
test('runs in parallel 1', async ({ page }) => {});
test('runs in parallel 2', async ({ page }) => {});
@ -571,14 +439,7 @@ Using serial is not recommended. It is usually better to make your tests isolate
**Usage**
```js tab=js-js
test.describe.serial('group', () => {
test('runs first', async ({ page }) => {});
test('runs second', async ({ page }) => {});
});
```
```js tab=js-ts
```js
test.describe.serial('group', () => {
test('runs first', async ({ page }) => {});
test('runs second', async ({ page }) => {});
@ -611,16 +472,7 @@ Using serial is not recommended. It is usually better to make your tests isolate
**Usage**
```js tab=js-js
test.describe.serial.only('group', () => {
test('runs first', async ({ page }) => {
});
test('runs second', async ({ page }) => {
});
});
```
```js tab=js-ts
```js
test.describe.serial.only('group', () => {
test('runs first', async ({ page }) => {
});
@ -651,15 +503,7 @@ Declares a skipped test group, similarly to [`method: Test.describe#1`]. Tests i
**Usage**
```js tab=js-js
test.describe.skip('skipped group', () => {
test('example', async ({ page }) => {
// This test will not run
});
});
```
```js tab=js-ts
```js
test.describe.skip('skipped group', () => {
test('example', async ({ page }) => {
// This test will not run
@ -756,17 +600,7 @@ export const test = base.extend<Options & { todoPage: TodoPage }>({
Then use the fixture in the test.
```js tab=js-js
// example.spec.js
const { test } = require('./my-test');
test('test 1', async ({ todoPage }) => {
await todoPage.addToDo('my todo');
// ...
});
```
```js tab=js-ts
```js
// example.spec.ts
import { test } from './my-test';
@ -834,16 +668,7 @@ Unconditionally marks a test as "should fail". Playwright Test runs this test an
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('not yet ready', async ({ page }) => {
test.fail();
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('not yet ready', async ({ page }) => {
@ -859,16 +684,7 @@ Conditionally mark a test as "should fail" with an optional description.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('fail in WebKit', async ({ page, browserName }) => {
test.fail(browserName === 'webkit', 'This feature is not implemented for Mac yet');
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('fail in WebKit', async ({ page, browserName }) => {
@ -897,20 +713,7 @@ Conditionally mark all tests in a file or [`method: Test.describe#1`] group as "
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.fail(({ browserName }) => browserName === 'webkit');
test('fail in WebKit 1', async ({ page }) => {
// ...
});
test('fail in WebKit 2', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.fail(({ browserName }) => browserName === 'webkit');
@ -943,15 +746,8 @@ Declares a test to be fixed, similarly to [`method: Test.(call)`]. This test wil
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.fixme('test to be fixed', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.fixme('test to be fixed', async ({ page }) => {
@ -980,16 +776,7 @@ Mark a test as "fixme", with the intention to fix it. Test is immediately aborte
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('test to be fixed', async ({ page }) => {
test.fixme();
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('test to be fixed', async ({ page }) => {
@ -1000,20 +787,7 @@ test('test to be fixed', async ({ page }) => {
Mark all tests in a file or [`method: Test.describe#1`] group as "fixme".
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.fixme();
test('test to be fixed 1', async ({ page }) => {
// ...
});
test('test to be fixed 2', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.fixme();
@ -1034,16 +808,7 @@ Conditionally mark a test as "fixme" with an optional description.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('broken in WebKit', async ({ page, browserName }) => {
test.fixme(browserName === 'webkit', 'This feature is not implemented on Mac yet');
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('broken in WebKit', async ({ page, browserName }) => {
@ -1075,20 +840,7 @@ Conditionally mark all tests in a file or [`method: Test.describe#1`] group as "
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.fixme(({ browserName }) => browserName === 'webkit');
test('broken in WebKit 1', async ({ page }) => {
// ...
});
test('broken in WebKit 2', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.fixme(({ browserName }) => browserName === 'webkit');
@ -1123,14 +875,7 @@ Returns information about the currently running test. This method can only be ca
**Usage**
```js tab=js-js
test('example test', async ({ page }) => {
// ...
await test.info().attach('screenshot', { body: await page.screenshot(), contentType: 'image/png' });
});
```
```js tab=js-ts
```js
test('example test', async ({ page }) => {
// ...
await test.info().attach('screenshot', { body: await page.screenshot(), contentType: 'image/png' });
@ -1145,13 +890,7 @@ Declares a focused test. If there are some focused tests or suites, all of them
**Usage**
```js tab=js-js
test.only('focus this test', async ({ page }) => {
// Run only focused tests in the entire project.
});
```
```js tab=js-ts
```js
test.only('focus this test', async ({ page }) => {
// Run only focused tests in the entire project.
});
@ -1181,7 +920,7 @@ Timeout for the currently running test is available through [`property: TestInfo
* Changing test timeout.
```js tab=js-ts
```js
test('very slow test', async ({ page }) => {
test.setTimeout(120000);
// ...
@ -1190,7 +929,7 @@ Timeout for the currently running test is available through [`property: TestInfo
* Changing timeout from a slow `beforeEach` or `afterEach` hook. Note that this affects the test timeout that is shared with `beforeEach`/`afterEach` hooks.
```js tab=js-ts
```js
test.beforeEach(async ({ page }, testInfo) => {
// Extend timeout for all tests running this hook by 30 seconds.
test.setTimeout(testInfo.timeout + 30000);
@ -1199,7 +938,7 @@ Timeout for the currently running test is available through [`property: TestInfo
* Changing timeout for a `beforeAll` or `afterAll` hook. Note this affects the hook's timeout, not the test timeout.
```js tab=js-ts
```js
test.beforeAll(async () => {
// Set timeout for this hook.
test.setTimeout(60000);
@ -1208,7 +947,7 @@ Timeout for the currently running test is available through [`property: TestInfo
* Changing timeout for all tests in a [`method: Test.describe#1`] group.
```js tab=js-ts
```js
test.describe('group', () => {
// Applies to all tests in this group.
test.describe.configure({ timeout: 60000 });
@ -1234,15 +973,7 @@ Declares a skipped test, similarly to [`method: Test.(call)`]. Skipped test is n
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.skip('broken test', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.skip('broken test', async ({ page }) => {
@ -1271,16 +1002,7 @@ Unconditionally skip a test. Test is immediately aborted when you call [`method:
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('skipped test', async ({ page }) => {
test.skip();
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('skipped test', async ({ page }) => {
@ -1291,20 +1013,7 @@ test('skipped test', async ({ page }) => {
Unconditionally skip all tests in a file or [`method: Test.describe#1`] group:
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.skip();
test('skipped test 1', async ({ page }) => {
// ...
});
test('skipped test 2', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.skip();
@ -1325,16 +1034,7 @@ Conditionally skip a test with an optional description.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('skip in WebKit', async ({ page, browserName }) => {
test.skip(browserName === 'webkit', 'This feature is not implemented for Mac');
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('skip in WebKit', async ({ page, browserName }) => {
@ -1345,16 +1045,7 @@ test('skip in WebKit', async ({ page, browserName }) => {
Skip from [`method: Test.beforeEach`] hook:
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({ page }) => {
test.skip(process.env.APP_VERSION === 'v1', 'There are no settings in v1');
await page.goto('/settings');
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }) => {
@ -1385,20 +1076,7 @@ Conditionally skips all tests in a file or [`method: Test.describe#1`] group.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.skip(({ browserName }) => browserName === 'webkit');
test('skip in WebKit 1', async ({ page }) => {
// ...
});
test('skip in WebKit 2', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.skip(({ browserName }) => browserName === 'webkit');
@ -1437,16 +1115,7 @@ Unconditionally marks a test as "slow". Slow test will be given triple the defau
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('slow test', async ({ page }) => {
test.slow();
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('slow test', async ({ page }) => {
@ -1462,16 +1131,7 @@ Conditionally mark a test as "slow" with an optional description. Slow test will
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('slow in WebKit', async ({ page, browserName }) => {
test.slow(browserName === 'webkit', 'This feature is slow on Mac');
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('slow in WebKit', async ({ page, browserName }) => {
@ -1500,20 +1160,7 @@ Conditionally mark all tests in a file or [`method: Test.describe#1`] group as "
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.slow(({ browserName }) => browserName === 'webkit');
test('slow in WebKit 1', async ({ page }) => {
// ...
});
test('slow in WebKit 2', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.slow(({ browserName }) => browserName === 'webkit');
@ -1547,17 +1194,7 @@ Declares a test step.
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('test', async ({ page }) => {
await test.step('Log in', async () => {
// ...
});
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
@ -1571,19 +1208,7 @@ test('test', async ({ page }) => {
The method returns the value retuned by the step callback.
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('test', async ({ page }) => {
const user = await test.step('Log in', async () => {
// ...
return 'john';
});
expect(user).toBe('john');
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
@ -1617,17 +1242,7 @@ Specifies options or fixtures to use in a single test file or a [`method: Test.d
**Usage**
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.use({ locale: 'en-US' });
test('test with locale', async ({ page }) => {
// Default context and page have locale as specified
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.use({ locale: 'en-US' });
@ -1643,23 +1258,7 @@ test('test with locale', async ({ page }) => {
It is also possible to override a fixture by providing a function.
```js tab=js-js
const { test, expect } = require('@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
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.use({

View File

@ -6,21 +6,7 @@ Playwright Test provides many options to configure how your tests are collected
Playwright Test supports running multiple test projects at the same time. Project-specific options should be put to [`property: TestConfig.projects`], but top-level [TestConfig] can also define base options shared between all projects.
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
timeout: 30000,
globalTimeout: 600000,
reporter: 'list',
testDir: './tests',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -52,23 +38,7 @@ Configuration for the `expect` assertion library. Learn more about [various time
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
expect: {
timeout: 10000,
toMatchSnapshot: {
maxDiffPixels: 10,
},
},
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -90,18 +60,7 @@ Whether to exit with an error if any tests or groups are marked as [`method: Tes
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
forbidOnly: !!process.env.CI,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -121,18 +80,7 @@ You can configure entire test run to concurrently execute all tests in all files
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
fullyParallel: true,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -151,18 +99,7 @@ Learn more about [global setup and teardown](../test-advanced.md#global-setup-an
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
globalSetup: './global-setup',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -181,18 +118,7 @@ Learn more about [global setup and teardown](../test-advanced.md#global-setup-an
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
globalTeardown: './global-teardown',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -209,18 +135,7 @@ Maximum time in milliseconds the whole test suite can run. Zero timeout (default
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
globalTimeout: process.env.CI ? 60 * 60 * 1000 : undefined,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -239,18 +154,7 @@ Filter to only run tests with a title matching one of the patterns. For example,
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
grep: /smoke/,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -269,18 +173,7 @@ Filter to only run tests with a title **not** matching one of the patterns. This
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
grepInvert: /manual/,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -297,18 +190,7 @@ Whether to skip snapshot expectations, such as `expect(value).toMatchSnapshot()`
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
ignoreSnapshots: !process.env.CI,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -327,18 +209,7 @@ Also available in the [command line](../test-cli.md) with the `--max-failures` a
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
maxFailures: process.env.CI ? 1 : 0,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -355,18 +226,7 @@ Metadata that will be put directly to the test report serialized as JSON.
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
metadata: 'acceptance tests',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -383,18 +243,7 @@ Config name is visible in the report and during test execution, unless overridde
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
name: 'acceptance tests',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -411,18 +260,7 @@ The output directory for files created during test execution. Defaults to `<pack
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
outputDir: './test-results',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -437,17 +275,7 @@ This directory is cleaned at the start. When running a test, a unique subdirecto
Here is an example that uses [`method: TestInfo.outputPath`] to create a temporary file.
```js tab=js-js
const { test, expect } = require('@playwright/test');
const fs = require('fs');
test('example test', async ({}, testInfo) => {
const file = testInfo.outputPath('temporary-file.txt');
await fs.promises.writeFile(file, 'Put some data to the file', 'utf8');
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
import fs from 'fs';
@ -467,18 +295,7 @@ The base directory, relative to the config file, for snapshot files created with
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
snapshotDir: './snapshots',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -508,18 +325,7 @@ Whether to preserve test output in the [`property: TestConfig.outputDir`]. Defau
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
preserveOutput: 'always',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -537,21 +343,7 @@ Playwright Test supports running multiple test projects at the same time. See [T
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { devices } = require('@playwright/test');
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
projects: [
{ name: 'chromium', use: devices['Desktop Chrome'] }
]
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
@ -570,18 +362,7 @@ Whether to suppress stdio and stderr output from the tests.
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
quiet: !!process.env.CI,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -598,18 +379,7 @@ The number of times to repeat each test, useful for debugging flaky tests.
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
repeatEach: 3,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -635,18 +405,7 @@ Learn more in the [reporters guide](../test-reporters.md).
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
reporter: 'line',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -665,18 +424,7 @@ Whether to report slow test files. Pass `null` to disable this feature.
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
reportSlowTests: null,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -697,18 +445,7 @@ The maximum number of retry attempts given to failed tests. By default failing t
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
retries: 2,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -729,18 +466,7 @@ Learn more about [parallelism and sharding](../test-parallel.md) with Playwright
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
shard: { total: 10, current: 3 },
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -757,18 +483,7 @@ Directory where the values accessible via [TestStore] are persisted. All pahts i
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
storeDir: './playwright-store',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -785,18 +500,7 @@ Directory that will be recursively scanned for test files. Defaults to the direc
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
testDir: './tests/playwright',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -815,18 +519,7 @@ For example, `'**/test-assets/**'` will ignore any files in the `test-assets` di
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
testIgnore: '**/test-assets/**',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -845,18 +538,7 @@ By default, Playwright Test looks for files matching `.*(test|spec)\.(js|ts|mjs)
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
testMatch: /.*\.e2e\.js/,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -875,18 +557,7 @@ This is a base timeout for all tests. In addition, each test can configure its o
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
timeout: 5 * 60 * 1000,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -908,18 +579,7 @@ Learn more about [snapshots](../test-snapshots.md).
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
updateSnapshots: 'missing',
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -936,20 +596,7 @@ Global options for all tests, for example [`property: TestOptions.browserName`].
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
use: {
browserName: 'chromium',
},
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -988,7 +635,7 @@ It is also recommended to specify [`property: TestOptions.baseURL`] in the confi
**Usage**
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
@ -1004,27 +651,9 @@ export default defineConfig({
});
```
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
webServer: {
command: 'npm run start',
port: 3000,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},
use: {
baseURL: 'http://localhost:3000/',
},
});
```
Now you can use a relative path when navigating the page:
```js tab=js-ts
```js
// test.spec.ts
import { test } from '@playwright/test';
@ -1034,19 +663,9 @@ test('test', async ({ page }) => {
});
```
```js tab=js-js
// test.spec.js
const { test } = require('@playwright/test');
test('test', async ({ page }) => {
// This will result in http://localhost:3000/foo
await page.goto('/foo');
});
```
Multiple web servers (or background processes) can be launched:
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
@ -1070,32 +689,6 @@ export default defineConfig({
});
```
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
webServer: [
{
command: 'npm run start',
port: 3000,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},
{
command: 'npm run backend',
port: 3333,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
}
],
use: {
baseURL: 'http://localhost:3000/',
},
});
```
## property: TestConfig.workers
* since: v1.10
- type: ?<[int]|[string]>
@ -1108,18 +701,7 @@ Defaults to half of the number of logical CPU cores. Learn more about [paralleli
**Usage**
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
workers: 3,
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';

View File

@ -4,16 +4,7 @@
`TestInfo` contains information about currently running test. It is available to any test function, [`method: Test.beforeEach`] and [`method: Test.afterEach`] hooks and test-scoped fixtures. `TestInfo` provides utilities to control test execution: attach files, update test timeout, determine which test is currently running and whether it was retried, etc.
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }, testInfo) => {
expect(testInfo.title).toBe('basic test');
await page.screenshot(testInfo.outputPath('screenshot.png'));
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }, testInfo) => {
@ -52,17 +43,7 @@ Attach a value or a file from disk to the current test. Some reporters show test
For example, you can attach a screenshot to the test:
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }, testInfo) => {
await page.goto('https://playwright.dev');
const screenshot = await page.screenshot();
await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' });
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }, testInfo) => {
@ -74,21 +55,11 @@ test('basic test', async ({ page }, testInfo) => {
Or you can attach files returned by your APIs:
```js tab=js-js
const { test, expect } = require('@playwright/test');
test('basic test', async ({}, testInfo) => {
const { download } = require('./my-custom-helpers');
const tmpPath = await download('a');
await testInfo.attach('downloaded', { path: tmpPath });
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
import { download } from './my-custom-helpers';
test('basic test', async ({}, testInfo) => {
const { download } = require('./my-custom-helpers');
const tmpPath = await download('a');
await testInfo.attach('downloaded', { path: tmpPath });
});
@ -171,16 +142,7 @@ Expected status for the currently running test. This is usually `'passed'`, exce
Expected status is usually compared with the actual [`property: TestInfo.status`]:
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.afterEach(async ({}, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus)
console.log(`${testInfo.title} did not run as expected!`);
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.afterEach(async ({}, testInfo) => {
@ -280,17 +242,7 @@ Absolute path to the output directory for this specific test run. Each test run
Returns a path inside the [`property: TestInfo.outputDir`] where the test can safely put a temporary file. Guarantees that tests running in parallel will not interfere with each other.
```js tab=js-js
const { test, expect } = require('@playwright/test');
const fs = require('fs');
test('example test', async ({}, testInfo) => {
const file = testInfo.outputPath('dir', 'temporary-file.txt');
await fs.promises.writeFile(file, 'Put some data to the dir/temporary-file.txt', 'utf8');
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
import fs from 'fs';
@ -336,24 +288,7 @@ Specifies a unique repeat index when running in "repeat each" mode. This mode is
Specifies the retry number when the test is retried after a failure. The first test run has [`property: TestInfo.retry`] equal to zero, the first retry has it equal to one, and so on. Learn more about [retries](../test-retries.md#retries).
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({}, testInfo) => {
// You can access testInfo.retry in any hook or fixture.
if (testInfo.retry > 0)
console.log(`Retrying!`);
});
test('my test', async ({ page }, testInfo) => {
// Here we clear some server-side state when retrying.
if (testInfo.retry)
await cleanSomeCachesOnTheServer();
// ...
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.beforeEach(async ({}, testInfo) => {
@ -377,16 +312,7 @@ Changes the timeout for the currently running test. Zero means no timeout. Learn
Timeout is usually specified in the [configuration file](../test-configuration.md), but it could be useful to change the timeout in certain scenarios:
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({ page }, testInfo) => {
// Extend timeout for all tests running this hook by 30 seconds.
testInfo.setTimeout(testInfo.timeout + 30000);
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }, testInfo) => {
@ -481,16 +407,7 @@ Actual status for the currently running test. Available after the test has finis
Status is usually compared with the [`property: TestInfo.expectedStatus`]:
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.afterEach(async ({}, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus)
console.log(`${testInfo.title} did not run as expected!`);
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.afterEach(async ({}, testInfo) => {
@ -519,16 +436,7 @@ Timeout in milliseconds for the currently running test. Zero means no timeout. L
Timeout is usually specified in the [configuration file](../test-configuration.md)
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.beforeEach(async ({ page }, testInfo) => {
// Extend timeout for all tests running this hook by 30 seconds.
testInfo.setTimeout(testInfo.timeout + 30000);
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }, testInfo) => {

View File

@ -6,23 +6,8 @@ Playwright Test provides many options to configure test environment, [Browser],
These options are usually provided in the [configuration file](../test-configuration.md) through [`property: TestConfig.use`] and [`property: TestProject.use`].
```js tab=js-js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
use: {
headless: false,
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,
video: 'on-first-retry',
},
});
```
```js tab=js-ts
import type { PlaywrightTestConfig } from '@playwright/test';
```js
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
headless: false,
@ -35,19 +20,7 @@ export default defineConfig({
Alternatively, with [`method: Test.use`] you can override some options for a file.
```js tab=js-js
// example.spec.js
const { test, expect } = require('@playwright/test');
// Run tests in this file with portrait-like viewport.
test.use({ viewport: { width: 600, height: 900 } });
test('my portrait test', async ({ page }) => {
// ...
});
```
```js tab=js-ts
```js
// example.spec.ts
import { test, expect } from '@playwright/test';
@ -71,20 +44,7 @@ test('my portrait test', async ({ page }) => {
Name of the browser that runs tests. Defaults to `'chromium'`. Most of the time you should set `browserName` in your [TestConfig]:
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
use: {
browserName: 'firefox',
},
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';

View File

@ -8,47 +8,7 @@ Playwright Test supports running multiple test projects at the same time. This i
Here is an example configuration that runs every test in Chromium, Firefox and WebKit, both Desktop and Mobile versions.
```js tab=js-js
// playwright.config.js
// @ts-check
const { devices } = require('@playwright/test');
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
// Options shared for all projects.
timeout: 30000,
use: {
ignoreHTTPSErrors: true,
},
// Options specific to each project.
projects: [
{
name: 'chromium',
use: devices['Desktop Chrome'],
},
{
name: 'firefox',
use: devices['Desktop Firefox'],
},
{
name: 'webkit',
use: devices['Desktop Safari'],
},
{
name: 'Mobile Chrome',
use: devices['Pixel 5'],
},
{
name: 'Mobile Safari',
use: devices['iPhone 12'],
},
],
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
@ -208,17 +168,7 @@ This directory is cleaned at the start. When running a test, a unique subdirecto
Here is an example that uses [`method: TestInfo.outputPath`] to create a temporary file.
```js tab=js-js
const { test, expect } = require('@playwright/test');
const fs = require('fs');
test('example test', async ({}, testInfo) => {
const file = testInfo.outputPath('temporary-file.txt');
await fs.promises.writeFile(file, 'Put some data to the file', 'utf8');
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
import fs from 'fs';
@ -256,48 +206,7 @@ Directory that will be recursively scanned for test files. Defaults to the direc
Each project can use a different directory. Here is an example that runs smoke tests in three browsers and all other tests in stable Chrome browser.
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
projects: [
{
name: 'Smoke Chromium',
testDir: './smoke-tests',
use: {
browserName: 'chromium',
}
},
{
name: 'Smoke WebKit',
testDir: './smoke-tests',
use: {
browserName: 'webkit',
}
},
{
name: 'Smoke Firefox',
testDir: './smoke-tests',
use: {
browserName: 'firefox',
}
},
{
name: 'Chrome Stable',
testDir: './',
use: {
browserName: 'chromium',
channel: 'chrome',
}
},
],
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';
@ -374,25 +283,7 @@ Use [`property: TestConfig.timeout`] to change this option for all projects.
Options for all tests in this project, for example [`property: TestOptions.browserName`]. Learn more about [configuration](../test-configuration.md) and see [available options][TestOptions].
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
projects: [
{
name: 'Chromium',
use: {
browserName: 'chromium',
},
},
],
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';

View File

@ -4,7 +4,7 @@
Playwright Test provides a global `store` object that can be used to read/write values on the filesystem. Each value is stored in its own file inside './playwright' directory, configurable with [`property: TestConfig.storeDir`].
```ts
```js
import { test, store } from '@playwright/test';
test('get user name', async ({ page, context }) => {

View File

@ -4,15 +4,7 @@
`WorkerInfo` contains information about the worker that is running tests. It is available to [`method: Test.beforeAll`] and [`method: Test.afterAll`] hooks and worker-scoped fixtures.
```js tab=js-js
const { test, expect } = require('@playwright/test');
test.beforeAll(async ({ browserName }, workerInfo) => {
console.log(`Running ${browserName} in worker #${workerInfo.workerIndex}`);
});
```
```js tab=js-ts
```js
import { test, expect } from '@playwright/test';
test.beforeAll(async ({ browserName }, workerInfo) => {

View File

@ -41,7 +41,7 @@ module.exports = MyReporter;
import { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
class MyReporter implements Reporter {
constructor(options: {customOption: { customOption?: string } = {}) {
constructor(options: { customOption?: string } = {}) {
console.log(`my-awesome-reporter setup with customOption set to ${options.customOption}`);
}
@ -66,18 +66,7 @@ export default MyReporter;
Now use this reporter with [`property: TestConfig.reporter`]. Learn more about [using reporters](../test-reporters.md).
```js tab=js-js
// playwright.config.js
// @ts-check
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
reporter: ['./my-awesome-reporter.js', { customOption: 'some value' }],
});
```
```js tab=js-ts
```js
// playwright.config.ts
import { defineConfig } from '@playwright/test';

View File

@ -1889,9 +1889,9 @@ export interface TestInfo {
*
* ```js
* import { test, expect } from '@playwright/test';
* import { download } from './my-custom-helpers';
*
* test('basic test', async ({}, testInfo) => {
* const { download } = require('./my-custom-helpers');
* const tmpPath = await download('a');
* await testInfo.attach('downloaded', { path: tmpPath });
* });
@ -3332,6 +3332,19 @@ type ConnectOptions = {
* value is stored in its own file inside './playwright' directory, configurable with
* [testConfig.storeDir](https://playwright.dev/docs/api/class-testconfig#test-config-store-dir).
*
* ```js
* import { test, store } from '@playwright/test';
*
* test('get user name', async ({ page, context }) => {
* await page.goto('/');
* // Return mock user info from the store.
* await page.route('**\/info/user', route => route.fulfill({ path: store.path('mocks/user.json')}))
* await page.getByText('My Profile');
* // Check that the name matches mock data.
* await expect(page.getByLabel('Name')).toHaveText('John');
* });
* ```
*
*/
export interface TestStore {
/**
@ -3371,7 +3384,7 @@ export interface TestStore {
* [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use).
*
* ```js
* import type { PlaywrightTestConfig } from '@playwright/test';
* import { defineConfig } from '@playwright/test';
* export default defineConfig({
* use: {
* headless: false,
@ -3498,7 +3511,7 @@ export type VideoMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry';
* [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use).
*
* ```js
* import type { PlaywrightTestConfig } from '@playwright/test';
* import { defineConfig } from '@playwright/test';
* export default defineConfig({
* use: {
* headless: false,

View File

@ -319,7 +319,7 @@ export interface FullResult {
* import { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
*
* class MyReporter implements Reporter {
* constructor(options: {customOption: { customOption?: string } = {}) {
* constructor(options: { customOption?: string } = {}) {
* console.log(`my-awesome-reporter setup with customOption set to ${options.customOption}`);
* }
*