diff --git a/packages/playwright-core/src/server/codegen/javascript.ts b/packages/playwright-core/src/server/codegen/javascript.ts index 17f627b601e22a..558670cd47842d 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.ts index a5d5cb6fcec9f3..d9f271e6e1ceda 100644 --- a/tests/library/inspector/cli-codegen-test.spec.ts +++ b/tests/library/inspector/cli-codegen-test.spec.ts @@ -84,18 +84,3 @@ test.use({ test('test', async ({ page }) => {`; await cli.waitFor(expectedResult); }); - -test('should work with --save-har', async ({ runCLI }, testInfo) => { - const harFileName = testInfo.outputPath('har.har'); - const expectedResult = ` - recordHar: { - mode: 'minimal', - path: '${harFileName.replace(/\\/g, '\\\\')}' - }`; - const cli = runCLI(['--target=playwright-test', `--save-har=${harFileName}`], { - autoExitWhen: expectedResult, - }); - await cli.waitForCleanExit(); - const json = JSON.parse(fs.readFileSync(harFileName, 'utf-8')); - expect(json.log.creator.name).toBe('Playwright'); -});