I'm trying to add a setup project to Playwright like the Auth documentations recommends:
Create a new setup project in the config and declare it as a dependency for all your testing projects. This project will always run and authenticate before all the tests. All testing projects should use the authenticated state as storageState.
The problem is that it doesn't recognize the auth.setup.ts
file or isn't running that test. I used this config:
export default defineConfig({
projects: [
{ name: "setup", testMatch: /.*\.setup\.ts/ },
{
testDir: "../.",
name: "CI",
use: {
baseURL: "http://localhost:5000",
browserName: "chromium",
headless: true,
storageState: "playwright/.auth/user.json",
},
},
],
dependencies: ["setup"],
globalTeardown: "./global-teardown",
globalSetup: "./global-setup",
});
I tried to put the file in different directories, change the regex, remove the globalSetup, and put the dependencies
property inside the use
object.
Any idea why this happens?
The dependencies
property should be included in a project definition. In your example, CI
depends on setup
and should look as follows.
export default defineConfig({
projects: [
{ name: "setup", testMatch: /.*\.setup\.ts/ },
{
testDir: "../.",
name: "CI",
// this project depends on `setup`
dependencies: ["setup"],
use: {
baseURL: "http://localhost:5000",
browserName: "chromium",
headless: true,
storageState: "playwright/.auth/user.json",
},
},
],
});