Rayrun

How do I modify the timeout settings in Playwright Test?

Answer

Change Global Timeout

To set a global timeout for the entire test run, update the globalTimeout property in playwright.config.ts using defineConfig(). For example, to set a global timeout of one hour:

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

export default defineConfig({
  globalTimeout: 60 * 60 * 1000,
});

Change Test Timeout

To change the timeout for each test, update the timeout property in playwright.config.ts using defineConfig(). For example, to set a timeout of five minutes:

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

export default defineConfig({
  timeout: 5 * 60 * 1000,
});

Change Timeout for Individual Tests

To change the timeout for a single test, use the setTimeout() method inside your test function. For example, to give a test two minutes before timing out:

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

test('slow test', async ({ page }) => {
  test.setTimeout(120000);
  await page.goto('https://ray.run/');
  // Your test code here
});

Change Timeout in Hooks

To extend or override timeouts in hooks like beforeEach() or beforeAll(), use the testInfo.setTimeout() method. For example, to extend all tests running with beforeEach() by an additional thirty seconds:

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

test.beforeEach(({ testInfo }) => {
  testInfo.setTimeout(testInfo.timeout + 30000);
});

test('example test', async ({ page }) => {
  await page.goto('https://ray.run/');
  // Your test code here
});

Note that Web-first assertions like expect(locator).toHaveText() have separate assertion timeouts, which can be changed using defineConfig() in playwright.config.ts.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.