Playwright: [Question] How to name video files

Created on 13 Oct 2020  路  11Comments  路  Source: microsoft/playwright

Hi team. I love the new video API in 1.5.0. Very clean. I don't see any information about how to name video files in the examples though. Seems like each file is just assigned a random name with no way to change that. When the API was in beta, we could get a handle to the file in order to rename it. Am I missing something in the docs?
https://playwright.dev/#path=docs%2Fverification.md&q=videos

Thanks!

P3-collecting-feedback

Most helpful comment

@pavelfeldman We have built some functionality using playwright-video that deletes videos for successful tests. Sometimes, tests are run in parallel which makes it difficult to determine which video file belongs to which test when using the new built-in video API in [email protected]. Being able to name each video recording when launching a new Page or Context would help use solve this issue.

When using playwright-video, we do the naming in a custom Jest test environment using the following logic:

  getVideoFilename(test: Circus.TestEntry): string {
    const parentName = test.parent.name.replace(/\W/g, "-");
    const specName = test.name.replace(/\W/g, "-");
    return `${parentName}_${specName}`;
  }

Additionally, let's say you run 10 tests at once and 5 of them fail. You will get 5 video files with randomly generated names. You'll have to look through all the videos in order to find which recording belongs to which test. I do not know what features you have planned here, but it would be a real pain not to be able to name the files. Could you maybe elaborate a bit on what you have planned around this going forward?

All 11 comments

Ouch, the name is in the trace, which is not yet public :/ Let us see what we can do to mitigate. Thanks for the early heads up!

Thanks for investigating @pavelfeldman. 馃憤

@celeryclub: we have a split in the team in terms of how we should handle this, please help us with sharing more details on your use case. We are going to have a trace info soon that will include the video name, so whatever API we add now is likely to not be needed in the future. So one of the options is to create contexts with unique folders and then scrape them for the video files. Does this work for you or you also need to know which page this video belongs to?

Still interested to know the use case!

@pavelfeldman We have built some functionality using playwright-video that deletes videos for successful tests. Sometimes, tests are run in parallel which makes it difficult to determine which video file belongs to which test when using the new built-in video API in [email protected]. Being able to name each video recording when launching a new Page or Context would help use solve this issue.

When using playwright-video, we do the naming in a custom Jest test environment using the following logic:

  getVideoFilename(test: Circus.TestEntry): string {
    const parentName = test.parent.name.replace(/\W/g, "-");
    const specName = test.name.replace(/\W/g, "-");
    return `${parentName}_${specName}`;
  }

Additionally, let's say you run 10 tests at once and 5 of them fail. You will get 5 video files with randomly generated names. You'll have to look through all the videos in order to find which recording belongs to which test. I do not know what features you have planned here, but it would be a real pain not to be able to name the files. Could you maybe elaborate a bit on what you have planned around this going forward?

My use case is pretty much the same as @Snikanes. I use playwright-video currently and I need to know the names in order to conditionally delete the video if the test passes, and in order to label the video if the test fails.

@Snikanes , @celeryclub : could you give playwright@next a try and tell us if the API in #4132 works for you? If yes, we will include it in 1.5.1 right away.

@pavelfeldman that solution will work for us, although I'm curious as to what you have planned long term with regard to the API. In the PR you mentioned, the following comment was made, where saveAs is mentioned. I'm not sure if I should read anything into this comment, but I personally believe that providing the path rather than having to rename the file on page/context close is a saner API. Could you shed some light on what the plans are going forward here?

Also, thanks for the quick reply :100:

Thanks for the fast follow-up! After further investigation, my first target will be using the official test runner, and then I'll revisit official video support since it appears to be built into the test runner.

Could you shed some light on what the plans are going forward here?

Providing the path is not always feasible - imagine a popup with the animation that appears upon user action. We need to start saving it right away, but we don't know the name yet. To eliminate this dependency, we are letting the browser pick the name and start recording in a non-blocking manner.

We assume that you create a new browser context for each test and specify a new folder for each of these contexts, so the idea is that you get a guid instead of a name, but it should be easy to associate it with the test run.

Hi all.
I have a lot of test suites, every test suite usually creates one context and do some actions in one or two of tabs.
So in my case probably the best way to divide video files is to create videos in separate folders.

But another feature that will be awesome to have - is an optional ability to set some pattern for video files. For example:
TestSuite1-<auto-generated-id>.avi

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TrySound picture TrySound  路  4Comments

juliomatcom picture juliomatcom  路  3Comments

etnbrd picture etnbrd  路  4Comments

VikramTiwari picture VikramTiwari  路  4Comments

JoelEinbinder picture JoelEinbinder  路  4Comments