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(codegen): do not codegen non-existing fixtures (#32993)
Pavel Feldman7047c3a6c6fd
diff --git a/packages/playwright-core/src/server/codegen/javascript.ts b/packages/playwright-core/src/server/codegen/javascript.tsindex 17f627b601..558670cd47 100644--- a/packages/playwright-core/src/server/codegen/javascript.ts+++ b/packages/playwright-core/src/server/codegen/javascript.ts@@ -138,7 +138,7 @@ export class JavaScriptLanguageGenerator implements LanguageGenerator {generateTestHeader(options: LanguageGeneratorOptions): string {const formatter = new JavaScriptFormatter();- const useText = formatContextOptions(options.contextOptions, options.deviceName);+ const useText = formatContextOptions(options.contextOptions, options.deviceName, this._isTest);formatter.add(`import { test, expect${options.deviceName ? ', devices' : ''} } from '@playwright/test';${useText ? '\ntest.use(' + useText + ');\n' : ''}@@ -157,7 +157,7 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''}(async () => {const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)});- const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName)});`);+ const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName, false)});`);return formatter.format();}@@ -199,8 +199,12 @@ function formatObjectOrVoid(value: any, indent = ' '): string {return result === '{}' ? '' : result;}-function formatContextOptions(options: BrowserContextOptions, deviceName: string | undefined): string {+function formatContextOptions(options: BrowserContextOptions, deviceName: string | undefined, isTest: boolean): string {const device = deviceName && deviceDescriptors[deviceName];+ if (isTest) {+ // No recordHAR fixture in test.+ options = { ...options, recordHar: undefined };+ }if (!device)return formatObjectOrVoid(options);// Filter out all the properties from the device descriptor.diff --git a/tests/library/inspector/cli-codegen-test.spec.ts b/tests/library/inspector/cli-codegen-test.spec.tsindex a5d5cb6fce..18eba82634 100644--- a/tests/library/inspector/cli-codegen-test.spec.ts+++ b/tests/library/inspector/cli-codegen-test.spec.ts@@ -85,13 +85,11 @@ test('test', async ({ page }) => {`;await cli.waitFor(expectedResult);});-test('should work with --save-har', async ({ runCLI }, testInfo) => {+test('should not generate recordHAR with --save-har', async ({ runCLI }, testInfo) => {const harFileName = testInfo.outputPath('har.har');- const expectedResult = `- recordHar: {- mode: 'minimal',- path: '${harFileName.replace(/\\/g, '\\\\')}'- }`;+ const expectedResult = `test.use({+ serviceWorkers: 'block'+});`;const cli = runCLI(['--target=playwright-test', `--save-har=${harFileName}`], {autoExitWhen: expectedResult,});