By default, Playwright sets a global timeout of 30 seconds for tests and actions. This means that if any test or action (such as navigating to a page or clicking a button) takes longer than 30 seconds, Playwright will automatically abort the test and mark it as failed due to a timeout. While this default behavior is useful in most cases, it may not be ideal for certain scenarios where longer waits are expected (e.g., when dealing with slow networks, complex pages, or large data).
In this guide, we will walk you through different ways to prevent Playwright tests from timing out after 30 seconds.
Adjusting Timeout for Specific Tests
If you only need to adjust the timeout for specific tests (e.g., one that requires more time due to complex operations), you can change the timeout at the individual test level.
Steps:
- Use test.setTimeout() in your test script to specify a timeout for a specific test.
- This allows you to keep the default timeout for most tests, but provide exceptions for tests that need more time.
Here’s an example of setting a timeout for a specific test:
// test.spec.ts import { test } from '@playwright/test'; test('long running test', async ({ page }) => { test.setTimeout(150_000); // Set timeout for this test to 150 seconds await page.goto('https://www.skptricks.com'); // Perform other actions... await page.waitForTimeout(120_000); });
In this example, the test.setTimeout() function sets the timeout to 60 seconds for that particular test.
You can refer the playwright official sites for more info https://playwright.dev/docs/test-timeouts#test-timeout
No comments:
Post a Comment