playwright: [BUG] Videos are not generated when reusing a single page between tests
Note from maintainers
As a workaround, we recommend recording a trace instead of a video. This will also give you much better debugging experience.
Context:
- Playwright Version: 1.22.2
- Operating System: Windows 11
- Node.js version: v 17.7.1
- Browser: chromium
- Extra: [any specific details about your environment]
System:
- OS: Windows 10 10.0.22000
- Memory: 1.24 GB / 15.79 GB
Binaries:
- Node: 17.7.1 - C:\Program Files\nodejs\node.EXE
- Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
- npm: 8.5.2 - C:\Program Files\nodejs\npm.CMD
Languages:
- Bash: 5.0.17 - C:\Windows\system32\bash.EXE
Code Snippet playwright.config.ts
const config: PlaywrightTestConfig = {
reporter: [['dot'],['html']],
use: {
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video:'retain-on-failure',
},
};
export default config;
broke.spec.ts (sourced from https://playwright.dev/docs/test-retries#reuse-single-page-between-tests)
import { test, Page } from '@playwright/test';
test.describe.configure({ mode: 'serial' });
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
await page.close();
});
test('a failing test', async () => {
await page.click('text=Get Started fail', {timeout: 1000}); // << deliberate fail
});
Describe the bug
Videos are not generated when reusing a single page between tests
Set the following configuration:
use: {
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
video:'retain-on-failure',
},
Run a failing test
Expected Result:
The spec above should successfully generate a screenshot, test steps, trace file and a video within the HTML result.
Actual Result:
The video is not being generated:

About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 90
- Comments: 72 (6 by maintainers)
Almost 2 years in and still an issue. I think this is very useful for debugging locally. I hope the Playwright core team starts looking into this with high priority š
Hi!
Iād expect this to be a higher prio bug (first report September 2021, almost š° šÆļø š )
Iām following the simple docs on overriding the page fixture, just as described, and I lose videos because of that? Since not fixing this, there should be a disclaimer on those docs imo
This is indeed a known issue: video recording produces a single video file from the creation of the page until its closure, as of Jun 2022.
Wondering if this can get a higher priority.
Iām also running into this issue - specifically, that video recording doesnāt work in pages created with
brower.newContext, as described here.My use case: Iām using
storageStatefor authentication, as described in the docs, except that I only want to use it for some tests. So when I need it, I callbrowser.newContext({ storageState: ... }). But then pages created from that context donāt get video recordings.For now I plan to use the
recordVideooption and manual file manipulation to emulatevideo: 'retain-on-failure'.Guys I have solved this problem in another way, this would be useful for someone who needs something like I did
Here is a little more context:
As many know the Playwright documentation is a bit ambiguous, and doesnāt show much in the way of examples that might be similar to reality.
In my case, I needed to enable videos only when a test case failed, such as video: āretain-on-failureā.
What happened, when Parallelism is implemented, it somehow makes the generic use of playwright.config.ts, unusable if you are using customFixtures, this makes it overwrite and retain some settings.
After solving the parallelism problem with multiple workers and different customFixtures to avoid crossing information, I found that it was necessary to create a new context (suggested by the documentation), this new context makes that the videos are not recorded and it is necessary to pass the configuration manually (since a new context is a manual context that we create on demand).
My solution was the following, keeping different contexts, enabling parallelism to keep the recordings when there is a failure (for debug or other purpose):
Iām having the same issue as @mweidner037. I use
storageStateand create pages frombrowser.newContext({ storageState: ... }). Iām trying to take retain videos on failure, but Iām not seeing any video recordings when my tests fail.this is my workaround for now in case it helps anyone. not too ugly. (Note: In this redacted example, I always save videos, this may not be what you want. You can use
testInfoto check the test status and conditionally save videos).PS: Playwright team, please update the docs for videos or browsercontexts to make it very clear that this āissueā/limitation exists and is not being prioritized
Hi @ryanrosello-og If you are picking the browser context configuration directly from xyz.config.js file and have not defined the context in the spec itself, then you would want to try the following configuration in order to get the videos generated.
use: { trace: āretain-on-failureā, screenshot: āonly-on-failureā, video:āretain-on-failureā, contextOptions: {recordVideo: { dir: ā<path_to_store_videos>/videos/'ā}} },
Iāve been using the solution I outlined in my previous comment for months; itās still working well. I did end up layering another fixture on top of that one for standard page object use.
Edit 9/22/23: cleaned up the fixture so it no longer throws a type error and doesnāt need a beforeAll hook @ibrocodes7
Fixture for enabling video recording:
Then I have my page object fixture:
Usage in spec file:
Just adding to this, Iām getting this on MacOS with Playwright version 1.29.1, so itās not just a windows OS issue.
@mxschmitt can you please help us to prioritise it?
this is an extension of @Derrbalās comment. This gets rid of the need to copy/paste the video saving logic within individual tests, by use of fixtures:
then within your test files you can do something like this:
The
adminRolePagefixture that is accessed intestin this example will automatically have a video recorded.Itās still reproducible on Playwright v1.42.1
It was mentioned above but this is an issue not just for custom fixtures or page reuse, but overriding storageState too, if you specify āretain-on-failureā. With mode āonā the video is captured. Iām guessing this is something about in retain-on-failure the videos arenāt written to the outputDir, but some temp location and only copied over if the test fails?
Iād really rather avoid having to write a custom fixture to get around this since I only need the storageState override for auth.
hey @dgozman , any plans on fixing this? Seems users are still hitting this issue. Some have proposed workarounds.
@ibrocodes7 This is hacky but I would just throw a
// @ts-expect-erroraboverecordVideo. I should revisit this soon and see if thereās a cleaner way to implement it. It is still working well for me; I have the fixture in an npm package that is used by a handful of Playwright projects daily and videos are still getting attached to my reports.We discovered a potential solution to allow us to create a video recording in a test which is using the browser fixture:
But adding this change accross all of our tests which uses the browser fixture is tome consuming and not ideal. We are hoping that someone has some ideas how we might abstract this change. We currently have extended test to use custom fixtures. It seems that it can be a good place to globally apply this fix but we are not sure how.
Hey Playwright team, just wanted to add my case to this ā the issue is still 100% reproducible even with the latest Playwright version.
To cut the story short - hereās my test repo https://github.com/alexzavg/playwright_retreat?tab=readme-ov-file#setup which can be easily cloned and installed and the issue can be clearly reproduced with this steps:
npm run setupin the project root foldernpm run chat:e2e:tests:prodnpm run show:reportto open the HTML reportā My Setup: video:
retain-on-failureset in the root config which is here:playwright.config.tsIām creating 2 browser contexts manually in
beforeAllin my spec file which is here:tests/chat/e2e/chat.spec.tsVideos are recorded correctly into
test-results/videos/ā I can see the.webmfiles after test runs.ā Problem: Videos do not show up in the HTML report. Only screenshots and traces appear. Hereās 2 images, one depicts part of the project file structure which clearly indicates that videos exist and another is the actual html report without the videos.
š§ Theory: It looks like Playwright only auto-attaches videos if the context is created internally by the test runner, not manually in beforeAll. Since I use dual contexts (to simulate 2 users), this breaks the automatic linkage.
š” Would love to see support for:
Appreciate the awesome work as always š
Hey @dgozman, even though I follow what has been suggested here
I indeed await
browserContext.close(), but there are no videos created.Also have this issue with re-using storageState
My test environment: npm list āāā @playwright/test@1.39.0 āāā @types/node@20.8.9 āāā dotenv@16.3.1 OS: MacOS 14.1 Chip: Apple M2 Max Browser: Chromium Version 119.0.6045.9 (Developer Build) (arm64)
Result: Adding the following to playwright.config.ts
Videos are generated in the output folder ātest-results/videosā. But I have to close the browser for each test, otherwise the video will be only generated once.
My apology, Iāve updated comment š
I think this problem is also present when using worker scoped fixtures. We get no video captures even if we use a new page instance for each test. Would be nice to have a fix for this.
Hi, Iām also facing the same issue with the Page object Model pattern, the video recording does not work. Waiting for the solution. My code looks like below,
`import { test, expect, Page} from ā@playwright/testā; import { LoginPage } from āā¦/pages/loginPageā;
let page: Page; let loginPage: LoginPage;
test.describe(āValidate login pageā, async () => {
test.beforeAll(async ({ browser }) => { page = await browser.newPage(); loginPage = new LoginPage(page);
});
test(ālogin page displayedā, async () => { await expect(loginPage.Title).toHaveText(āABCā); await expect(loginPage.Title).toContainText(āLog inā); });
test(ātest Aā, async () => { expect('A).toEqual(testA); });
test(ātestBā, async () => { expect('B).toEqual(testB); });
test.afterAll(async () => { console.log(āLogin page validated successfullyā); await page.close(); });`
I have the same problem with reusing StorageState as @mweidner037 and @KeionneDerousselle described.
I believe I have this working with a fixture but itās not pretty. A worker-scoped fixture initiates video recording to a temp dir and clean up of that dir on teardown. A test-scoped fixture attaches the video to the test reports on failure or time out.
fixture:
usage: