installationdependenciesplaywrightteardown

How do i run a teardown project in playwright even if there are failures in the e2e_tests project


I have managed to run setup before all the tests and teardown after all the tests . i need to run teardown no matter whether e2e_tests are successful or not as currently it only runs if all e2e_tests are passed . what changes i should do in below projects.

projects: [
        {
            name: 'setup',
            testMatch: /global\.setup\.ts/,
          },
        {
            name: 'e2e_tests',
            use: {
                ...devices['Desktop Chrome'],
            },
            dependencies: ['setup'],
        },
        {
            name: 'teardown',
            testMatch: /global\.teardown\.ts/,
            dependencies: ['e2e_tests'],
          },
    ],

thought of changing dependencies but dependencies order is correct it is just that the teardwon should not be dependent on whether e2e_tests are successful or not.


Solution

  • Setting the teardown property on the setup projects solves it. Here, teardown will always run - even if tests in e2e_tests project fails:

      projects: [
        {
          name: "setup",
          testMatch: /global\.setup\.ts/,
          teardown: "teardown",  // <---- added
        },
        {
          name: "e2e_tests",
          use: {
            ...devices["Desktop Chrome"],
          },
          dependencies: ["setup"],
        },
        {
          name: "teardown",
          testMatch: /global\.teardown\.ts/,
          // removed dependency to setup project
        },
      ],