mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
6d491f928d
This configuration option allows to set a string with template values for precise control over snapshot path location. An example of `snapshotPathTemplate` usage: ```ts // playwright.config.ts // Notice the `testDir` configuration! export default { testDir: './tests', snapshotPathTemplate: './__screenshots__/{platform}/{projectName}/{testFilePath}/{arg}{ext}', } ``` Currently supported "magic tokens" inside the `snapshotPathTemplate` are: - `{testDir}` - project's `testDir` - `{snapshotDir}` - project's `snapshotDir` - `{platform}` - `process.platform` - `{projectName}` - Project's sanitized name - `{testFileDir}` - Directories in relative path from `testDir` to test file path (e.g. `page/` in the example below) - `{testFileName}` - Test file name (with extension) (e.g. `page-click.spec.ts` in the example below) - `{testFilePath}` - Relative path from `testDir` to test file path (e.g. `page/page-click.spec.ts` in the example below) - `{ext}` - snapshot extension (with dots) - `{arg}` - joined snapshot name parts, without extension (e.g. `foo/bar/baz` in the example below) - `{snapshotSuffix}` - `testInfo.snapshotSuffix` value. Consider the following file structure: ``` playwright.config.ts tests/ └── page/ └── page-click.spec.ts ``` The following `page-click.spec.ts`: ```ts // page-click.spec.ts import { test, expect } from '@playwright/test'; test('should work', async ({ page }) => { await expect(page).toHaveScreenshot(['foo', 'bar', 'baz.png']); }); ``` Fixes #7792
115 lines
4.2 KiB
TypeScript
Executable File
115 lines
4.2 KiB
TypeScript
Executable File
/**
|
|
* Copyright (c) Microsoft Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
import { test, expect } from './npmTest';
|
|
import * as path from 'path';
|
|
import { TestServer } from '../../utils/testserver';
|
|
|
|
|
|
// Skipping docker tests on CI on non-linux since GHA does not have
|
|
// Docker engine installed on macOS and Windows.
|
|
test.skip(() => process.env.CI && process.platform !== 'linux');
|
|
|
|
test.beforeAll(async ({ exec }) => {
|
|
// Delete any previous docker image to ensure clean run.
|
|
await exec('npx playwright docker delete-image', {
|
|
cwd: path.join(__dirname, '..', '..'),
|
|
});
|
|
});
|
|
|
|
test('make sure it tells to run `npx playwright docker build` when image is not installed', async ({ exec }) => {
|
|
await exec('npm i --foreground-scripts @playwright/test');
|
|
const result = await exec('npx playwright docker start', {
|
|
expectToExitWithError: true,
|
|
});
|
|
expect(result).toContain('npx playwright docker build');
|
|
});
|
|
|
|
test.describe('installed image', () => {
|
|
test.beforeAll(async ({ exec, daemonProcess, waitForPort }) => {
|
|
await exec('npx playwright docker build', {
|
|
env: { PWTEST_DOCKER_BASE_IMAGE: 'playwright:installation-tests-focal' },
|
|
cwd: path.join(__dirname, '..', '..'),
|
|
});
|
|
const dockerProcess = await daemonProcess({
|
|
command: ['npx', 'playwright', 'docker', 'start', '--port=5667'],
|
|
shell: true,
|
|
cwd: path.join(__dirname, '..', '..'),
|
|
});
|
|
await dockerProcess.waitForOutput('- Endpoint:');
|
|
});
|
|
|
|
test.afterAll(async ({ exec }) => {
|
|
await exec('npx playwright docker delete-image', {
|
|
cwd: path.join(__dirname, '..', '..'),
|
|
});
|
|
});
|
|
|
|
test('all browsers work headless', async ({ exec }) => {
|
|
await exec('npm i --foreground-scripts @playwright/test');
|
|
const result = await exec('npx playwright test docker.spec.js --grep platform --browser all', {
|
|
env: { PLAYWRIGHT_DOCKER: '1' },
|
|
});
|
|
expect(result).toContain('@chromium Linux');
|
|
expect(result).toContain('@webkit Linux');
|
|
expect(result).toContain('@firefox Linux');
|
|
});
|
|
|
|
test('all browsers work headed', async ({ exec }) => {
|
|
await exec('npm i --foreground-scripts @playwright/test');
|
|
{
|
|
const result = await exec(`npx playwright test docker.spec.js --headed --grep userAgent --browser chromium`, {
|
|
env: { PLAYWRIGHT_DOCKER: '1' },
|
|
});
|
|
expect(result).toContain('@chromium');
|
|
expect(result).not.toContain('Headless');
|
|
expect(result).toContain(' Chrome/');
|
|
}
|
|
{
|
|
const result = await exec(`npx playwright test docker.spec.js --headed --grep userAgent --browser webkit`, {
|
|
env: { PLAYWRIGHT_DOCKER: '1' },
|
|
});
|
|
expect(result).toContain('@webkit');
|
|
expect(result).toContain(' Version/');
|
|
}
|
|
{
|
|
const result = await exec(`npx playwright test docker.spec.js --headed --grep userAgent --browser firefox`, {
|
|
env: { PLAYWRIGHT_DOCKER: '1' },
|
|
});
|
|
expect(result).toContain('@firefox');
|
|
expect(result).toContain(' Firefox/');
|
|
}
|
|
});
|
|
|
|
test('port forwarding works', async ({ exec, tmpWorkspace }) => {
|
|
await exec('npm i --foreground-scripts @playwright/test');
|
|
const TEST_PORT = 8425;
|
|
const server = await TestServer.create(tmpWorkspace, TEST_PORT);
|
|
server.setRoute('/', (request, response) => {
|
|
response.end('Hello from host');
|
|
});
|
|
const result = await exec('npx playwright test docker.spec.js --grep localhost --browser all', {
|
|
env: {
|
|
TEST_PORT: TEST_PORT + '',
|
|
PLAYWRIGHT_DOCKER: '1'
|
|
},
|
|
});
|
|
expect(result).toContain('@chromium Hello from host');
|
|
expect(result).toContain('@webkit Hello from host');
|
|
expect(result).toContain('@firefox Hello from host');
|
|
});
|
|
});
|
|
|