Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(screenshot): account for `screenshot === undefined` (#19627)
Dmitry Gozmand12bc0be9ad0
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex 4443f22485..5f157fc722 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -20,7 +20,7 @@ import type { APIRequestContext, BrowserContext, BrowserContextOptions, LaunchOpimport * as playwrightLibrary from 'playwright-core';import { createGuid, debugMode } from 'playwright-core/lib/utils';import { removeFolders } from 'playwright-core/lib/utils/fileUtils';-import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestInfo, TestType, TraceMode, VideoMode } from '../types/test';+import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, ScreenshotMode, TestInfo, TestType, TraceMode, VideoMode } from '../types/test';import { store as _baseStore } from './store';import type { TestInfoImpl } from './testInfo';import { rootTestType, _setProjectSetup } from './testType';@@ -246,8 +246,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({if (debugMode())testInfo.setTimeout(0);- const screenshotOptions = typeof screenshot !== 'string' ? { fullPage: screenshot.fullPage, omitBackground: screenshot.omitBackground } : undefined;- const screenshotMode = typeof screenshot === 'string' ? screenshot : screenshot.mode;+ const screenshotMode = normalizeScreenshotMode(screenshot);+ const screenshotOptions = typeof screenshot === 'string' ? undefined : screenshot;const traceMode = normalizeTraceMode(trace);const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };@@ -620,6 +620,12 @@ export function shouldCaptureTrace(traceMode: TraceMode, testInfo: TestInfo) {return traceMode === 'on' || traceMode === 'retain-on-failure' || (traceMode === 'on-first-retry' && testInfo.retry === 1);}+function normalizeScreenshotMode(screenshot: PlaywrightWorkerOptions['screenshot'] | undefined): ScreenshotMode {+ if (!screenshot)+ return 'off';+ return typeof screenshot === 'string' ? screenshot : screenshot.mode;+}+const kTracingStarted = Symbol('kTracingStarted');export const test = _baseTest.extend<TestFixtures, WorkerFixtures>(playwrightFixtures);diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.tsindex daa856f51a..7956c6123b 100644--- a/tests/playwright-test/playwright.spec.ts+++ b/tests/playwright-test/playwright.spec.ts@@ -600,3 +600,86 @@ test('should pass fixture defaults to tests', async ({ runInlineTest }) => {expect(result.exitCode).toBe(0);expect(result.passed).toBe(1);});++test('should not throw with many fixtures set to undefined', async ({ runInlineTest }, testInfo) => {+ const result = await runInlineTest({+ 'playwright.config.ts': `+ module.exports = { use: {+ headless: undefined,+ channel: undefined,+ launchOptions: undefined,+ connectOptions: undefined,+ screenshot: undefined,+ video: undefined,+ trace: undefined,+ acceptDownloads: undefined,+ bypassCSP: undefined,+ colorScheme: undefined,+ deviceScaleFactor: undefined,+ extraHTTPHeaders: undefined,+ geolocation: undefined,+ hasTouch: undefined,+ httpCredentials: undefined,+ ignoreHTTPSErrors: undefined,+ isMobile: undefined,+ javaScriptEnabled: undefined,+ locale: undefined,+ offline: undefined,+ permissions: undefined,+ proxy: undefined,+ storageState: undefined,+ timezoneId: undefined,+ userAgent: undefined,+ viewport: undefined,+ actionTimeout: undefined,+ testIdAttribute: undefined,+ navigationTimeout: undefined,+ baseURL: undefined,+ serviceWorkers: undefined,+ contextOptions: undefined,+ } };+ `,+ 'a.spec.ts': `+ const { test } = pwt;+ test.use({+ headless: undefined,+ channel: undefined,+ launchOptions: undefined,+ connectOptions: undefined,+ screenshot: undefined,+ video: undefined,+ trace: undefined,+ acceptDownloads: undefined,+ bypassCSP: undefined,+ colorScheme: undefined,+ deviceScaleFactor: undefined,+ extraHTTPHeaders: undefined,+ geolocation: undefined,+ hasTouch: undefined,+ httpCredentials: undefined,+ ignoreHTTPSErrors: undefined,+ isMobile: undefined,+ javaScriptEnabled: undefined,+ locale: undefined,+ offline: undefined,+ permissions: undefined,+ proxy: undefined,+ storageState: undefined,+ timezoneId: undefined,+ userAgent: undefined,+ viewport: undefined,+ actionTimeout: undefined,+ testIdAttribute: undefined,+ navigationTimeout: undefined,+ baseURL: undefined,+ serviceWorkers: undefined,+ contextOptions: undefined,+ });+ test('passes', async ({ page }) => {+ });+ `,+ }, { workers: 1 });++ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});