Introduction

Playwright is an increasingly used browser automation tool for end-to-end testing, especially for non-regression tests. Playwright has the ability to record videos of your tests. Dont forget to read the introduction post.

In this article, we will discuss how to set up Playwright to record videos, the benefits of this feature, and how to use it effectively.

Configuring Playwright for Video Recording

To start, you need to set up Playwright to record videos of your tests.

This is quite simple to do. In your Playwright configuration file, simply add the recordVideo option. You can specify the path where the videos will be saved with the dir option. For example: recordVideo: { dir: 'videos/' }.

From this point, Playwright will record a video for each test run.

My playwright.config.ts file contains the following lines

  use: {
    video: 'on',
    trace: 'on-first-retry',
  },

and for my video recording test, I add a recordVideo parameter when opening the browser in the code

  const context = await browser.newContext(
            {
                httpCredentials:
                {
                    username: 'julienbrouwers',
                    password: 'xxxxxx'
                },
                recordVideo:{ dir : './playwright-videos-tests/' },
            })

Advantages of Video Recording

Recording videos of your tests offers many advantages. First of all, it allows you to see exactly what happened during the test. If a test fails, you can watch the video to see where and how it failed.

It is a good tool for debugging, it can also be useful for sharing, documentation, and training.

You can show new team members how the tests are supposed to run, or use the videos to demonstrate the user journey, technical limitations, or problems to stakeholders and clients…

Only in the Command Line

Beware! Videos only record in the command line, if you run your tests from your Visual Studio Code, the video won’t record! I lost a little time on this subtlety on my side.

Conclusion

In conclusion, video recording offers Playwright is a tool worth exploring.

It is simple to set up and offers many advantages, to adapt according to our contexts and needs!

Discover how to set up Playwright to record videos of your tests. Learn the benefits of this feature and how to use it effectively for debugging, sharing, documentation, and training.

Categorized in: