[Bug]: Codegen can't track `openPage`
Version
1.45.0
Steps to reproduce
-
npx playwright codegen https://example.com - Open new tab
- Enter
https://example.com/
Expected behavior
Codegen generates valid test code like this:
import { test, expect } from '@playwright/test';
test('test', async ({ page, context }) => {
await page.goto('https://example.com/');
const page1 = await context.newPage()
await page1.goto('https://example.com/');
});
Actual behavior
https://github.com/microsoft/playwright/assets/1796864/7cbc8036-f6a9-470c-af09-8917fa3dac31
Codegen generates invalid code:
import { test, expect } from '@playwright/test';
test('test', async ({ page }) => {
await page.goto('https://example.com/');
await page1.goto('https://example.com/');
});
Additional context
I believe it worked at some point but it doesn't work with Playwright 1.44.1 as well. Perhaps browser version can be related to the cause.
Environment
$ npx envinfo --preset playwright
System:
OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Memory: 9.00 GB / 15.54 GB
Container: Yes
Binaries:
Node: 20.13.1 - ~/.local/share/mise/installs/node/20/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 10.8.0 - ~/.local/share/mise/installs/node/20/bin/npm
IDEs:
VSCode: 1.90.2 - /home/mtsmfm/.vscode-server/bin/5437499feb04f7a586f677b155b039bc2b3669eb/bin/remote-cli/code
Languages:
Bash: 5.0.17 - /usr/bin/bash
npmPackages:
@playwright/test: 1.45.0 => 1.45.0
playwright: 1.45.0 => 1.45.0
I'm having the exact same behaviour, and generated code is definitely invalid
Looking at the source code, openPage and closePage actions are ignored in playwright test mode:
https://github.com/microsoft/playwright/blob/fc19e6e7b4224bb9acecb89cbd73a8646a63eccf/packages/playwright-core/src/server/codegen/javascript.ts#L39-L40
I understand the reason: only page fixture is injected (it's the only one needed in 99% of the scenarios). Nevertheless, I think it would be easy to fix, as long as the generateHeader also received the actions, and that way it would be possible to decide whether include the context fixture or not.
Why was this issue closed?
Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.
Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.