playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: Add CLI option to leave headed browser open after running test

Open f-w opened this issue 1 year ago • 3 comments

🚀 Feature Request

Add CLI option for example --leave-browser-open. When specified, browser will be left open after running test(s). The option is only effective in conjunction with --headed option.

Example

on OOTB Playwright project, runing

npx playwright test --headed --leave-browser-open --project=chromium example

leaves chromium browser open after test.

Motivation

A script may have 2 use cases

  1. fully automated regression test
  2. as a booster to manual UAT

For example, a CRM web app typically requires login, creating a contact, then a service request. A script automating such workflow can be used standalone, or can be used by a manual UAT tester to save time on these common repetitive steps at the begining, then contintue with subsequent less common manual workflow. In the latter case, browser session needs to be preserved after testing is complete.

Adding pause at script end won't work because case 1 is also impacted.

Browser will be left open by default when launched by VS Code. But VS Code should be optional, especially for manual UAT testers who just need to run rather than compose scripts.

f-w avatar Jun 16 '24 19:06 f-w

@f-w It seems like you already know about the available alternatives - VSCode extension, page.pause(), etc. I do not really understand why it does not work for you.

Just in case, the following snippet that uses environment variables should be 100% equivalent to the proposed option:

test('example', async ({ page }) => {
  // ... test goes here ... 

  if (process.env.LEAVE_BROWSER_OPEN)
    await page.pause();
});

You can run it with LEAVE_BROWSER_OPEN=1 npx playwright test. Let me know whether this helps.

dgozman avatar Jun 17 '24 18:06 dgozman

@dgozman, --leave-browser-open option gives test runners a more consistant user experience than your proposal because test scripts can be authored by different people. It is not trivial to enforce all scripts contain the same code block you gave. The consistant user experience is a more important concern especially when test runners are less technical savvy to have the capacity to inspect source to figure out why some scripts work as expected and others don't.

f-w avatar Jun 17 '24 19:06 f-w

@f-w You can structure the code to avoid putting this snippet everywhere. For example, by introducing an automatic fixture, or overriding the page fixture.

I am recommending a DIY solution to unblock you, because I don't expect this feature to be implemented soon.

dgozman avatar Jun 17 '24 19:06 dgozman