Search code examples
typescriptplaywright

How to ignore multiple spec files in playwright?


in my config i have 3 projects, one runs tests for a specific acc type using one login, the other runs tests for another login, and now ive just added a 3rd project that has to run tests for a specific browser.

Problem is, I need the second project to also ignore tests from the third project as well as the first.

My config looks like this:

  projects: [
    {
      name: 'Basic Users',
      testMatch: /.*limited.spec.ts/,
      use: {
        baseURL: process.env.URL,
        screenshot: "only-on-failure",
        video: "retain-on-failure",
        storageState: 'login1.json', 
        headless: true,
        viewport: { width: 1536, height: 850 },
        ignoreHTTPSErrors: true,
      } 
    },
    {
      name: 'Admin Users',
      testIgnore: /.*limited.spec.ts/,
      use: {
        baseURL: process.env.URL,
        screenshot: "only-on-failure",
        video: "retain-on-failure",
        storageState: 'login2.json', 
        headless: true,
        viewport: { width: 1536, height: 850 },
        ignoreHTTPSErrors: true,
      } 
    },
    {
      name: 'Comment Tests',
      testMatch: /.*comments.spec.ts/,
      use: {
        baseURL: process.env.URL,
        screenshot: "only-on-failure",
        video: "retain-on-failure",
        storageState: 'login2.json', 
        headless: true,
        channel: 'chrome',
        viewport: { width: 1536, height: 850 },
        ignoreHTTPSErrors: true,
      } 
    }
  ]
};
export default config;

I basically need to ignore the comment tests from running in the admin project


Solution

  • If you wish to ignore several files that located in different locations, you can use an Array instead of a single string/regex, since testIgnore type is string | RegExp | Array<string | RegExp>.

    For example:

    projects: [
        {
          name: "Admin",
          testIgnore: [
            "/userOnlyFolder/**/*.spec.ts", // Any test file under a specified folder or anywhere under it's sub-directories
            "**/userOnlyTestFile.spec.ts", // A specific test file anywhere in the folder tree
            "/tests/someOtherFolder/userOnlyTestFile.spec.ts", // Full path specified
          ],
        },
    ]
    

    Playwright testconfig ignore docs