1

I want to run global setup before all the tests using project configuration. This is my playwright.config.ts file -

import { defineConfig  } from '@playwright/test';
require('dotenv').config();

export default defineConfig({
    testDir: './tests',
    timeout: 60 * 1000,
    expect: {
        timeout: 5000
    },
    forbidOnly: !!process.env.CI,
    workers: process.env.WORKERS ? +process.env.WORKERS : undefined,
    projects: [
        {
            name: "setup",
            testMatch: /.*\.setup\.ts/ ,
            setTimeout: 60 * 1000,
        },
        {
            name: "chrome",
            dependencies: ['setup'],
            use: {
                headless: true,
                browserName: "chromium",
                viewport: { width: 1280, height: 720 },
                ignoreHTTPSErrors: true
            },
            testMatch: '**/*.spec.ts'
        }
    ],
    reporter: [["list"], ["junit"]]
});

I have one global.setup.ts file in the same location as of playwright.config.ts. And all the test files are present in the directory ./tests/

This is the snapshot of my global.setup.ts file - enter image description here

But my global.setup.ts file is not running before the tests. How to fix this?

  • not able to see the issue, but you can call the global setup like this https://playwright.dev/docs/test-configuration#advanced-configuration – tushi43 Jul 01 '23 at 10:31

1 Answers1

0

I just spent god knows how long working out this same issue!.

The issue I had was the *.setup.ts file should be in the same place the tests are, not the config file. Move that file to the ./tests folder and report back if it works or not!.

Greener
  • 183
  • 11
  • I'm battling with the same, setup.js in the same folder as tests. some of the tests run even before the setup is started and the result of the setup is entirely ignored. without setup it reports running 6 tests in 6 workers, with setup it says 7 tests in 6 workers. – webduvet Aug 03 '23 at 12:49