skip to Main Content

I have Test A in folder A1 and Test B in folder B1.

Using PlaywrightJS I would like to execute all of the tests inside folder B1 ONLY if everything inside folder A1 passes without any failures. The runner should stop if there are any failures. How can I do this?

2

Answers


  1. It’s not a cool thing to write dependent tests, but if you need it, you can use Project dependencies

    import { defineConfig } from '@playwright/test';
    
    export default defineConfig({
      maxFailures: 1,
      projects: [
        {
          name: 'A',
          testMatch: '*/dirA/*.ts',
        },
        {
          name: 'B',
          testMatch: '*/dirB/*.ts',
          dependencies: ['A'],
       },
      ]
    });
    

    The runner should stop if there are any failures.

    maxFailures: 1

    But still – it’s better to use before/after hooks and test steps if you need to split test logic.

    Login or Signup to reply.
  2. You can achieve this and have your tests independent at the same time by specifying a separate CLI command (e.g., npm script) for the tests in folder A (run-tests-in-a) and the tests in folder B (run-tests-in-b) and then define a command that uses && CLI operator (run-tests-in-a && run-tests-in-b).

    I understand that this is a bit more "hacky" than desired, but for a good reason. The general agreement is that tests should be written in an independent way (all tests make no assumptions about other tests), and so this behaviour of a conditional run cannot be a concern of the test framework.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search