← Back to Discord Forum

Elapsed time of a Test

I have an E2E suite that has some long and short tests based on duration. So I have configured a elapsed timeout for each. This timeout is based on a normal run time with an added contingency for possible API retries or page retries to give the test the benefit of the doubt. What I would like to do is have a way to assert that the elapsed timeout is still operating in designated threshold. So, can I after each test assert the timeout is still valid? This could alert us when we might have some drift based on test data or data indexing that could be shifting to slower runs. Maybe someone has a better solution, happy to discuss. Just thought it might be easier to have the test tell me that it has drifted form our designated thresholds. I know the elapsed time is reportable but wondering how I can access it, Thanks!

This thread is trying to answer question "Can I assert the validity of the elapsed timeout for each test in an E2E suite and how can I access the elapsed time report?"

0 replies


Sure, you can validate the elapsed timeout for each test in your e2e suite with @playwright/test. It offers configurable timeouts for different tasks, including test timeouts. By default, the test timeout is 30 seconds.

You can use the test.setTimeout() function to set a custom timeout for a single test or modify the timeout within hooks like beforeAll and afterAll.

Here's how you can extend the timeout for all tests running within a specific hook by 30 seconds:

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

test.beforeEach(async ({}, testInfo) => {
  // Extend timeout for all tests running this hook by 30 seconds.
  testInfo.setTimeout(testInfo.timeout + 30000);

And here's how you can change the timeout specifically for a beforeAll or afterAll hook:

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

test.beforeAll(async () => {
  // Set custom timeout for this beforeAll hook.

Remember, assertion timeouts are separate from overall e2e suite timeouts. Assertion timeouts are related to web-first assertions like expect(locator).toHaveText(), which have their own default value of 5 seconds but can be customized in the Playwright Test configuration file (playwright.config.ts).

To set a global timeout for the entire test run, you can define it in the playwright.config.ts file using defineConfig. For example, you can set a global timeout of one hour (3600 seconds) as follows:

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

export default defineConfig({
  timeout: 3600000, // One hour in milliseconds

By modifying these timeouts and asserting their validity using appropriate conditions or assertions provided by your testing framework (such as Jest's expect), you can ensure that each individual e2e test adheres to its specified timeout duration.

Related Discord Threads

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.