test: roll to folio@0.4.0-alpha28 (#6918)
@ -3,7 +3,7 @@ id: test-snapshots
|
||||
title: "Visual comparisons"
|
||||
---
|
||||
|
||||
Playwright Test includes the ability to produce and visually compare screenshots using `expect(value).toMatchSnapshot()`. On first execution, Playwright test will generate reference screenshots. Subsequent runs will compare against the reference.
|
||||
Playwright Test includes the ability to produce and visually compare screenshots using `expect(value).toMatchSnapshot(snapshotName)`. On first execution, Playwright test will generate reference screenshots. Subsequent runs will compare against the reference.
|
||||
|
||||
```js js-flavor=js
|
||||
// example.spec.js
|
||||
@ -11,7 +11,7 @@ const { test, expect } = require('@playwright/test');
|
||||
|
||||
test('example test', async ({ page }) => {
|
||||
await page.goto('https://playwright.dev');
|
||||
expect(await page.screenshot()).toMatchSnapshot('optional-snapshot-name.png');
|
||||
expect(await page.screenshot()).toMatchSnapshot('snapshot-name.png');
|
||||
});
|
||||
```
|
||||
|
||||
@ -21,7 +21,7 @@ import { test, expect } from '@playwright/test';
|
||||
|
||||
test('example test', async ({ page }) => {
|
||||
await page.goto('https://playwright.dev');
|
||||
expect(await page.screenshot()).toMatchSnapshot('optional-snapshot-name.png');
|
||||
expect(await page.screenshot()).toMatchSnapshot('snapshot-name.png');
|
||||
});
|
||||
```
|
||||
|
||||
@ -39,7 +39,7 @@ const { test, expect } = require('@playwright/test');
|
||||
|
||||
test('example test', async ({ page }) => {
|
||||
await page.goto('https://playwright.dev');
|
||||
expect(await page.screenshot()).toMatchSnapshot({ threshold: 0.2 });
|
||||
expect(await page.screenshot()).toMatchSnapshot('home.png', { threshold: 0.2 });
|
||||
});
|
||||
```
|
||||
|
||||
@ -49,11 +49,11 @@ import { test, expect } from '@playwright/test';
|
||||
|
||||
test('example test', async ({ page }) => {
|
||||
await page.goto('https://playwright.dev');
|
||||
expect(await page.screenshot()).toMatchSnapshot({ threshold: 0.2 });
|
||||
expect(await page.screenshot()).toMatchSnapshot('home.png', { threshold: 0.2 });
|
||||
});
|
||||
```
|
||||
|
||||
Apart from screenshots, `expect(value).toMatchSnapshot()` can also be used to compare text, png and jpeg images, or arbitrary binary data. Playwright Test auto-detects the content type and uses the appropriate comparison algorithm.
|
||||
Apart from screenshots, `expect(value).toMatchSnapshot(snapshotName)` can also be used to compare text, png and jpeg images, or arbitrary binary data. Playwright Test auto-detects the content type and uses the appropriate comparison algorithm.
|
||||
|
||||
Here we compare text content against the reference.
|
||||
|
||||
@ -63,7 +63,7 @@ const { test, expect } = require('@playwright/test');
|
||||
|
||||
test('example test', async ({ page }) => {
|
||||
await page.goto('https://playwright.dev');
|
||||
expect(await page.textContent('.hero__title')).toMatchSnapshot();
|
||||
expect(await page.textContent('.hero__title')).toMatchSnapshot('hero.txt');
|
||||
});
|
||||
```
|
||||
|
||||
@ -73,8 +73,8 @@ import { test, expect } from '@playwright/test';
|
||||
|
||||
test('example test', async ({ page }) => {
|
||||
await page.goto('https://playwright.dev');
|
||||
expect(await page.textContent('.hero__title')).toMatchSnapshot();
|
||||
expect(await page.textContent('.hero__title')).toMatchSnapshot('hero.txt');
|
||||
});
|
||||
```
|
||||
|
||||
Snapshots are stored next to the test file, in a separate directory. For example, `my.spec.js` file will produce and store snapshots in the `my.spec.js-snapshots` directory. You should commit this directory to your version control (e.g. `git`), and review any changes to it.
|
||||
Snapshots are stored next to the test file, in a separate directory. For example, `my.spec.ts` file will produce and store snapshots in the `my.spec.ts-snapshots` directory. You should commit this directory to your version control (e.g. `git`), and review any changes to it.
|
||||
|
14
package-lock.json
generated
@ -55,7 +55,7 @@
|
||||
"eslint-plugin-notice": "^0.9.10",
|
||||
"eslint-plugin-react-hooks": "^4.2.0",
|
||||
"file-loader": "^6.1.0",
|
||||
"folio": "=0.4.0-alpha27",
|
||||
"folio": "=0.4.0-alpha28",
|
||||
"formidable": "^1.2.2",
|
||||
"html-webpack-plugin": "^4.4.1",
|
||||
"ncp": "^2.0.0",
|
||||
@ -4199,9 +4199,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/folio": {
|
||||
"version": "0.4.0-alpha27",
|
||||
"resolved": "https://registry.npmjs.org/folio/-/folio-0.4.0-alpha27.tgz",
|
||||
"integrity": "sha512-IjCe0ds6N++F2rVKGHm8lXLqH4smGiwZMP5tylFR7PQykU+i9eGKka1TtxXxhReAH9DMEb3+YRWfzZZdF43MXg==",
|
||||
"version": "0.4.0-alpha28",
|
||||
"resolved": "https://registry.npmjs.org/folio/-/folio-0.4.0-alpha28.tgz",
|
||||
"integrity": "sha512-sbHdEDRXPkkhzHAyRy/tQKTWImNy38cICoii4ox9AGYFVWgF+i4l37AL2cVfJkUEvUqZpq+u4NkuV1cMelV5AA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.12.13",
|
||||
@ -13205,9 +13205,9 @@
|
||||
}
|
||||
},
|
||||
"folio": {
|
||||
"version": "0.4.0-alpha27",
|
||||
"resolved": "https://registry.npmjs.org/folio/-/folio-0.4.0-alpha27.tgz",
|
||||
"integrity": "sha512-IjCe0ds6N++F2rVKGHm8lXLqH4smGiwZMP5tylFR7PQykU+i9eGKka1TtxXxhReAH9DMEb3+YRWfzZZdF43MXg==",
|
||||
"version": "0.4.0-alpha28",
|
||||
"resolved": "https://registry.npmjs.org/folio/-/folio-0.4.0-alpha28.tgz",
|
||||
"integrity": "sha512-sbHdEDRXPkkhzHAyRy/tQKTWImNy38cICoii4ox9AGYFVWgF+i4l37AL2cVfJkUEvUqZpq+u4NkuV1cMelV5AA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.12.13",
|
||||
|
@ -80,7 +80,7 @@
|
||||
"eslint-plugin-notice": "^0.9.10",
|
||||
"eslint-plugin-react-hooks": "^4.2.0",
|
||||
"file-loader": "^6.1.0",
|
||||
"folio": "=0.4.0-alpha27",
|
||||
"folio": "=0.4.0-alpha28",
|
||||
"formidable": "^1.2.2",
|
||||
"html-webpack-plugin": "^4.4.1",
|
||||
"ncp": "^2.0.0",
|
||||
|
@ -21,7 +21,8 @@ import type { PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, P
|
||||
|
||||
export * from 'folio';
|
||||
export const test = folio.test.extend<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>({
|
||||
browserName: [ 'chromium', { scope: 'worker' } ],
|
||||
defaultBrowserType: [ 'chromium', { scope: 'worker' } ],
|
||||
browserName: [ ({ defaultBrowserType }, use) => use(defaultBrowserType), { scope: 'worker' } ],
|
||||
playwright: [ require('../inprocess'), { scope: 'worker' } ],
|
||||
headless: [ undefined, { scope: 'worker' } ],
|
||||
channel: [ undefined, { scope: 'worker' } ],
|
||||
@ -66,8 +67,8 @@ export const test = folio.test.extend<PlaywrightTestArgs & PlaywrightTestOptions
|
||||
viewport: undefined,
|
||||
contextOptions: {},
|
||||
|
||||
context: async ({ browserName, browser, screenshot, video, acceptDownloads, bypassCSP, colorScheme, deviceScaleFactor, extraHTTPHeaders, hasTouch, geolocation, httpCredentials, ignoreHTTPSErrors, isMobile, javaScriptEnabled, locale, offline, permissions, proxy, storageState, viewport, timezoneId, userAgent, contextOptions }, use, testInfo) => {
|
||||
testInfo.snapshotSuffix = browserName + '-' + process.platform;
|
||||
context: async ({ browser, screenshot, video, acceptDownloads, bypassCSP, colorScheme, deviceScaleFactor, extraHTTPHeaders, hasTouch, geolocation, httpCredentials, ignoreHTTPSErrors, isMobile, javaScriptEnabled, locale, offline, permissions, proxy, storageState, viewport, timezoneId, userAgent, contextOptions }, use, testInfo) => {
|
||||
testInfo.snapshotSuffix = process.platform;
|
||||
if (process.env.PWDEBUG)
|
||||
testInfo.setTimeout(0);
|
||||
|
||||
@ -148,3 +149,5 @@ export const test = folio.test.extend<PlaywrightTestArgs & PlaywrightTestOptions
|
||||
},
|
||||
});
|
||||
export default test;
|
||||
|
||||
export const __baseTest = folio.test;
|
||||
|
@ -87,18 +87,16 @@ export function addTestCommand(program: commander.CommanderStatic) {
|
||||
}
|
||||
|
||||
async function runTests(Runner: RunnerType, args: string[], opts: { [key: string]: any }) {
|
||||
if (opts.browser) {
|
||||
const browserOpt = opts.browser.toLowerCase();
|
||||
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
|
||||
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
|
||||
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
|
||||
defaultConfig.projects = browserNames.map(browserName => {
|
||||
return {
|
||||
name: browserName,
|
||||
use: { browserName },
|
||||
};
|
||||
});
|
||||
}
|
||||
const browserOpt = opts.browser ? opts.browser.toLowerCase() : 'chromium';
|
||||
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
|
||||
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
|
||||
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
|
||||
defaultConfig.projects = browserNames.map(browserName => {
|
||||
return {
|
||||
name: browserName,
|
||||
use: { browserName },
|
||||
};
|
||||
});
|
||||
|
||||
const overrides = overridesFromOptions(opts);
|
||||
if (opts.headed)
|
||||
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -101,7 +101,7 @@ class DefaultMode {
|
||||
}
|
||||
}
|
||||
|
||||
const baseFixtures: folio.Fixtures<{ __baseSetup: void }, BaseOptions & BaseFixtures> = {
|
||||
const baseFixtures: folio.Fixtures<{}, BaseOptions & BaseFixtures> = {
|
||||
mode: [ 'default', { scope: 'worker' } ],
|
||||
browserName: [ 'chromium' , { scope: 'worker' } ],
|
||||
channel: [ undefined, { scope: 'worker' } ],
|
||||
@ -123,10 +123,6 @@ const baseFixtures: folio.Fixtures<{ __baseSetup: void }, BaseOptions & BaseFixt
|
||||
isWindows: [ process.platform === 'win32', { scope: 'worker' } ],
|
||||
isMac: [ process.platform === 'darwin', { scope: 'worker' } ],
|
||||
isLinux: [ process.platform === 'linux', { scope: 'worker' } ],
|
||||
__baseSetup: [ async ({ browserName }, run, testInfo) => {
|
||||
testInfo.snapshotSuffix = browserName;
|
||||
await run();
|
||||
}, { auto: true } ],
|
||||
};
|
||||
|
||||
type ServerOptions = {
|
||||
|
@ -48,7 +48,7 @@ const metadata = {
|
||||
};
|
||||
|
||||
config.projects.push({
|
||||
name: 'electron',
|
||||
name: 'chromium', // We use 'chromium' here to share screenshots with chromium.
|
||||
use: {
|
||||
mode: 'default',
|
||||
browserName: 'chromium',
|
||||
@ -59,7 +59,7 @@ config.projects.push({
|
||||
});
|
||||
|
||||
config.projects.push({
|
||||
name: 'electron',
|
||||
name: 'chromium', // We use 'chromium' here to share screenshots with chromium.
|
||||
use: {
|
||||
mode: 'default',
|
||||
browserName: 'chromium',
|
||||
|
Before Width: | Height: | Size: 475 B After Width: | Height: | Size: 475 B |
Before Width: | Height: | Size: 333 B After Width: | Height: | Size: 333 B |
Before Width: | Height: | Size: 443 B After Width: | Height: | Size: 443 B |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
@ -153,7 +153,7 @@ it('focused input should produce the same screenshot', async ({browserType, brow
|
||||
it.skip(browserName === 'webkit' && platform === 'linux', 'gtk vs wpe');
|
||||
it.skip(!!process.env.CRPATH);
|
||||
|
||||
testInfo.snapshotSuffix = browserName + '-' + platform;
|
||||
testInfo.snapshotSuffix = platform;
|
||||
|
||||
const headful = await browserType.launch({...browserOptions, headless: false });
|
||||
const headfulPage = await headful.newPage();
|
||||
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 474 B After Width: | Height: | Size: 474 B |
Before Width: | Height: | Size: 311 B After Width: | Height: | Size: 311 B |
Before Width: | Height: | Size: 445 B After Width: | Height: | Size: 445 B |
Before Width: | Height: | Size: 138 B After Width: | Height: | Size: 138 B |
Before Width: | Height: | Size: 109 B After Width: | Height: | Size: 109 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 113 B After Width: | Height: | Size: 113 B |
Before Width: | Height: | Size: 142 B After Width: | Height: | Size: 142 B |
Before Width: | Height: | Size: 134 B After Width: | Height: | Size: 134 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 181 B |
Before Width: | Height: | Size: 153 B After Width: | Height: | Size: 153 B |
Before Width: | Height: | Size: 179 B After Width: | Height: | Size: 179 B |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 181 B After Width: | Height: | Size: 181 B |
Before Width: | Height: | Size: 153 B After Width: | Height: | Size: 153 B |
Before Width: | Height: | Size: 179 B After Width: | Height: | Size: 179 B |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 181 B |
Before Width: | Height: | Size: 153 B |
Before Width: | Height: | Size: 179 B |
Before Width: | Height: | Size: 311 B |
Before Width: | Height: | Size: 474 B |
Before Width: | Height: | Size: 311 B |
Before Width: | Height: | Size: 445 B |
Before Width: | Height: | Size: 474 B |
Before Width: | Height: | Size: 311 B |
Before Width: | Height: | Size: 445 B |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 257 B After Width: | Height: | Size: 257 B |
Before Width: | Height: | Size: 206 B After Width: | Height: | Size: 206 B |
Before Width: | Height: | Size: 256 B After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 301 B After Width: | Height: | Size: 301 B |
Before Width: | Height: | Size: 200 B After Width: | Height: | Size: 200 B |
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 94 B After Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 75 B After Width: | Height: | Size: 75 B |
Before Width: | Height: | Size: 97 B After Width: | Height: | Size: 97 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 73 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 1.9 KiB |