chore: fix docs (#18751)

This commit is contained in:
Andrey Lushnikov 2022-11-11 13:44:40 -08:00 committed by GitHub
parent 7685c929bf
commit 251cc9e229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 1 deletions

View File

@ -1369,6 +1369,19 @@ const config: PlaywrightTestConfig = {
export default config; export default config;
``` ```
```js tab=js-js
// playwright.config.js
// @ts-check
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
testDir: './tests',
snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
};
module.exports = config;
```
The value might include some "tokens" that will be replaced with actual values during test execution. The value might include some "tokens" that will be replaced with actual values during test execution.
Consider the following file structure: Consider the following file structure:
@ -1382,7 +1395,7 @@ tests/
And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call: And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:
```ts ```js tab=js-ts
// page-click.spec.ts // page-click.spec.ts
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
@ -1393,6 +1406,17 @@ 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: The list of supported tokens:
* `{testDir}` - Project's [`property: TestConfig.testDir`]. * `{testDir}` - Project's [`property: TestConfig.testDir`].
@ -1434,6 +1458,23 @@ const config: PlaywrightTestConfig = {
export default config; export default config;
``` ```
```js tab=js-js
// playwright.config.js
// @ts-check
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
snapshotPathTemplate: '__screenshots__{/projectName}/{testFilePath}/{arg}{ext}',
testMatch: 'example.spec.ts',
projects: [
{ use: { browserName: 'firefox' } },
{ name: 'chromium', use: { browserName: 'chromium' } },
],
};
module.exports = config;
```
In this config: In this config:
1. First project **does not** have a name, so its snapshots will be stored in `<configDir>/__screenshots__/example.spec.ts/...`. 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/..`. 1. Second project **does** have a name, so its snapshots will be stored in `<configDir>/__screenshots__/chromium/example.spec.ts/..`.

View File

@ -805,6 +805,17 @@ interface TestConfig {
* *
* And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call: * And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:
* *
* ```js
* // page-click.spec.ts
* import { test, expect } from '@playwright/test';
*
* test.describe('suite', () => {
* test('test should work', async ({ page }) => {
* await expect(page).toHaveScreenshot(['foo', 'bar', 'baz.png']);
* });
* });
* ```
*
* The list of supported tokens: * The list of supported tokens:
* - `{testDir}` - Project's [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir). * - `{testDir}` - Project's [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).
* - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with config) * - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with config)
@ -4595,6 +4606,17 @@ interface TestProject {
* *
* And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call: * And the following `page-click.spec.ts` that uses `toHaveScreenshot()` call:
* *
* ```js
* // page-click.spec.ts
* import { test, expect } from '@playwright/test';
*
* test.describe('suite', () => {
* test('test should work', async ({ page }) => {
* await expect(page).toHaveScreenshot(['foo', 'bar', 'baz.png']);
* });
* });
* ```
*
* The list of supported tokens: * The list of supported tokens:
* - `{testDir}` - Project's [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir). * - `{testDir}` - Project's [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir).
* - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with config) * - Value: `/home/playwright/tests` (absolute path is since `testDir` is resolved relative to directory with config)