diff --git a/packages/playwright-core/src/server/codegen/javascript.ts b/packages/playwright-core/src/server/codegen/javascript.ts index 18ea3d885e..428ca493f8 100644 --- a/packages/playwright-core/src/server/codegen/javascript.ts +++ b/packages/playwright-core/src/server/codegen/javascript.ts @@ -146,7 +146,7 @@ export class JavaScriptLanguageGenerator implements LanguageGenerator { ${useText ? '\ntest.use(' + useText + ');\n' : ''} test('test', async ({ page }) => {`); if (options.contextOptions.recordHar) - formatter.add(` await page.routeFromHAR('${options.contextOptions.recordHar.path}');`); + formatter.add(` await page.routeFromHAR(${quote(options.contextOptions.recordHar.path)});`); return formatter.format(); } @@ -163,7 +163,7 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''} const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)}); const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName, false)});`); if (options.contextOptions.recordHar) - formatter.add(` await context.routeFromHAR('${options.contextOptions.recordHar.path}');`); + formatter.add(` await context.routeFromHAR(${quote(options.contextOptions.recordHar.path)});`); return formatter.format(); } diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.ts index cfbd96fb57..f7c68b4544 100644 --- a/packages/playwright/src/matchers/matchers.ts +++ b/packages/playwright/src/matchers/matchers.ts @@ -140,7 +140,7 @@ export function toBeVisible( const expected = visible ? 'visible' : 'hidden'; const unexpected = visible ? 'hidden' : 'visible'; const arg = visible ? '' : '{ visible: false }'; - return toBeTruthy.call(this, 'toBeVisibleFoo', locator, 'Locator', expected, unexpected, arg, async (isNot, timeout) => { + return toBeTruthy.call(this, 'toBeVisible', locator, 'Locator', expected, unexpected, arg, async (isNot, timeout) => { return await locator._expect(visible ? 'to.be.visible' : 'to.be.hidden', { isNot, timeout }); }, options); } diff --git a/tests/library/inspector/cli-codegen-csharp.spec.ts b/tests/library/inspector/cli-codegen-csharp.spec.ts index 5ccb8d67e5..865b916bef 100644 --- a/tests/library/inspector/cli-codegen-csharp.spec.ts +++ b/tests/library/inspector/cli-codegen-csharp.spec.ts @@ -170,7 +170,7 @@ await context.StorageStateAsync(new BrowserContextStorageStateOptions test('should work with --save-har', async ({ runCLI }, testInfo) => { const harFileName = testInfo.outputPath('har.har'); - const expectedResult = `await context.RouteFromHARAsync("${harFileName}");` + const expectedResult = `await context.RouteFromHARAsync(${JSON.stringify(harFileName)});`; const cli = runCLI(['--target=csharp', `--save-har=${harFileName}`], { autoExitWhen: expectedResult, }); @@ -201,7 +201,7 @@ for (const testFramework of ['nunit', 'mstest'] as const) { test(`should work with --save-har in ${testFramework}`, async ({ runCLI }, testInfo) => { const harFileName = testInfo.outputPath('har.har'); - const expectedResult = `await context.RouteFromHARAsync("${harFileName}");` + const expectedResult = `await context.RouteFromHARAsync("${harFileName}");`; const cli = runCLI([`--target=csharp-${testFramework}`, `--save-har=${harFileName}`], { autoExitWhen: expectedResult, }); diff --git a/tests/library/inspector/cli-codegen-java.spec.ts b/tests/library/inspector/cli-codegen-java.spec.ts index 72aaf77fd8..93f55132ed 100644 --- a/tests/library/inspector/cli-codegen-java.spec.ts +++ b/tests/library/inspector/cli-codegen-java.spec.ts @@ -91,7 +91,7 @@ test('should print load/save storage_state', async ({ runCLI, browserName }, tes test('should work with --save-har', async ({ runCLI }, testInfo) => { const harFileName = testInfo.outputPath('har.har'); - const expectedResult = `context.routeFromHAR("${harFileName}");`; + const expectedResult = `context.routeFromHAR(${JSON.stringify(harFileName)});`; const cli = runCLI(['--target=java', `--save-har=${harFileName}`], { autoExitWhen: expectedResult, }); diff --git a/tests/library/inspector/cli-codegen-test.spec.ts b/tests/library/inspector/cli-codegen-test.spec.ts index 4336ffff10..d76caee422 100644 --- a/tests/library/inspector/cli-codegen-test.spec.ts +++ b/tests/library/inspector/cli-codegen-test.spec.ts @@ -87,7 +87,7 @@ test('test', async ({ page }) => {`; test('should not generate recordHAR with --save-har', async ({ runCLI }, testInfo) => { const harFileName = testInfo.outputPath('har.har'); - const expectedResult = ` await page.routeFromHAR('${harFileName}');`; + const expectedResult = ` await page.routeFromHAR('${harFileName.replace(/\\/g, '\\\\')}');`; const cli = runCLI(['--target=playwright-test', `--save-har=${harFileName}`], { autoExitWhen: expectedResult, }); @@ -99,7 +99,7 @@ test('should not generate recordHAR with --save-har', async ({ runCLI }, testInf test('should generate routeFromHAR with --save-har', async ({ runCLI }, testInfo) => { const harFileName = testInfo.outputPath('har.har'); const expectedResult = `test('test', async ({ page }) => { - await page.routeFromHAR('${harFileName}'); + await page.routeFromHAR('${harFileName.replace(/\\/g, '\\\\')}'); });`; const cli = runCLI(['--target=playwright-test', `--save-har=${harFileName}`], { autoExitWhen: expectedResult,