1

I know that we can set timeout for all the tests using Playwright.config.ts file or through command line argument. Also we can set timeout for each of the tests separately using test.setTimeout() at the beginning of the test. But in my scenario, I want to add timeout in the globalSetup.ts file which runs before all the tests. globalSetup

Currently it is getting timed out at 30 seconds which is the default test timeout of playwright. But my website takes longer than 30 seconds to load in global setup file.

1 Answers1

1

From v1.31 onwards you can configure your global setup as a Playwright project dependency and apply the required settings including timeout.

Example:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'setup',
      testMatch: /global.setup\.ts/,
    },
    {
      name: 'chromium',
      use: devices['Desktop Chrome'],
      dependencies: ['setup'],
    },
    {
      name: 'firefox',
      use: devices['Desktop Firefox'],
      dependencies: ['setup'],
    },
    {
      name: 'webkit',
      use: devices['Desktop Safari'],
      dependencies: ['setup'],
    },
  ],
});
Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23
  • Thanks, one more question on this method of project configuration. What if there are more than 1 projects in my config file? Will all of them contain testMatch attribute for dependency on 'setup' project? Or this should be defined only on the top project and the rest will depend on this top project? – Saurav Likhar Jun 30 '23 at 19:12