playwrightplaywright-test

Playwright- How to set timeout for globalsetup.ts file?


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.


Solution

  • 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'],
        },
      ],
    });