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,
});
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,
});
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
});
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
.
If you still have questions, please ask a question and I will try to answer it.
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 [email protected].