What is the recommended way to configure global teardown in Playwright?


Recommended Way to Configure Global Teardown in Playwright

To configure global teardown in Playwright, you can use either a global teardown file or project dependencies. However, the recommended method is using project dependencies, as it allows your HTML report to show the global teardown, trace viewer to record a trace of the teardown, and fixtures to be used.

Project dependencies are a list of projects that need to run before the tests in another project run. They are useful for configuring global teardown actions so that one project depends on this running first. Using dependencies allows global teardown to produce traces and other artifacts.

To set up global teardown using project dependencies, follow these steps:

  1. Create a new project in your Playwright configuration file.
  2. Add a globalTeardown option to the new project and specify the path to the teardown file.
  3. In the main project, add a dependsOn option and reference the new project.

Here's an example of how to configure global teardown using project dependencies:

// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  projects: [
      name: 'Global Teardown',
      globalTeardown: './global-teardown.ts',
      name: 'Main Project',
      use: { baseURL: 'https://ray.run' },
      dependsOn: ['Global Teardown'],

export default config;

In the global-teardown.ts file, export a single function that takes a config object. This function will be run once after all tests have completed.

// global-teardown.ts
import { FullConfig } from '@playwright/test';

export default async function globalTeardown(config: FullConfig): Promise<void> {
  // Your teardown logic here

By using project dependencies, you can ensure proper execution order and produce traces and other artifacts for your global teardown.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.