playwright: [BUG] Some config options are working only partially when using browser.newContext()

Context:

  • Playwright Version: 1.14.1
  • Operating System: Linux
  • Node.js version: v14.16.0
  • Browser: chromium

Code Snippet

  1. Clone this repo: https://github.com/xrash/pwt-config-issue-example
  2. Run yarn
  3. Run npx playwright test
  4. The directory test-results will be created with partial output
  5. Open playwright.config.ts and remove the use option altogether
  6. Run npx playwright test again
  7. The directory test-results won’t even be created this time

Describe the bug

The fixture options under use at the config file are working only partially when creating a new context manually (browser.newContext()).

For instance, trace and screenshot work, but video doesn’t record any video at all. Also, trace doesn’t fully work, as trace is recorded per test even when the context is created in beforeAll or in a worker-scoped fixture (desired behavior is to have the trace for the entire context session in one file). Also, the trace file seems buggy or incomplete.

If the fixture options under use in the config file aren’t supposed to work when using browser.newContext(), then I’d expect it not to work at all, instead of having them to work only partially; and if it’s supposed to work, then I’d expect it to work fully.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Thanks @dgozman . Perhaps beyond the scope of this ticket but where does BrowserContext sits within BeforeAll hooks? A few months ago when I started on my current framework, I couldn’t reuse the context because the BeforeAll hook wouldn’t allow it.

To reiterate, we do not suggest reusing the context, but rather reusing the browser (that happens automatically). However, if you’d really like to reuse page/context, take a look at this doc.

@spaniardmaximus Playwright Test starts a single browser per worker, shared by many tests, out of the box. However, creating a new BrowserContext per test is cheap and gives test isolation. I suggest to try the default way first before you hit any performance issues. You can read more about contexts and isolation here.

We are facing the same issue . Has anyone found a work around to only record video on failure on newContext. Able to record video by passing recordVideo Object on newContext await browser.newContext({storageState: storageState,recordVideo: {dir: ‘videos/’}}) .But I believe it has no association with config