Skip to content

[Feature] Run dependencies based on tag in test name #23080

@leesangb

Description

@leesangb

Let us know what functionality you'd like to see in Playwright and what your use case is.
Do you think others might benefit from this as well?

Feature:

I want to run dependencies based on tag in test name.

Currently, I can use dependencies array to run some "setup" before running my tests
Here is an example:

// playwright.config.ts
export default defineConfig({
  // ...
  projects: [
    {
      name: 'setup',
      testMatch: 'setup/global.setup.ts'
      // ...
    },
    {
      name: 'some test',
      testMatch: 'tests/with-global-setup/*.test.ts',
      dependencies: ['setup'],
      // ...
    }
  ],
});

This approach works well when there are only a few dependencies like above. However, when I want multiple dependencies, it becomes a bit challenging to structure the project. I have to create another folder depth or add some custom naming convention in my test file in order to combine dependencies + testMatch + grep

Use case:

I want to skip some dependencies even if the test matches the pattern in the configuration without creating another project configuration. This becomes necessary when there are too many combinations of dependencies. For example, if I want to run different setups for mobile/desktop, dark/light mode, user/guest/admin, and other variations.

  • It may be useful when you want to combine setups conditionally.

Proposal:

// playwright.config.ts
export default defineConfig({
  // ...
  projects: [
    {
      name: 'setupA',
      testMatch: 'setup/global.setup.ts'
      // ...
    },
    {
      name: 'setupB',
      testMatch: 'setup/global.setup.ts'
      // ...
    },
    {
      name: 'setupC',
      testMatch: 'setup/global.setup.ts'
      // ...
    },
    {
      name: 'some test',
      testMatch: 'tests/with-setups/*.test.ts',
      dependencies: ['setupA', 'setupB', 'setupC'],
      // ...
    }
  ],
});
// tests/with-setups/something.test.ts

test('test something with @setupA @setupC', async () => {
  // run setupA then setupC (setupB is skipped) then do stuff
});

test('test something with @setupB @setupA', async () => {
  // run setupB then setupA then do stuff
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions