typescriptui-automationplaywrightplaywright-test

How to increase timeout for a specific action/test only?


I have a timeout for 2 mins in PlaywrightTestConfig file as a Global setting. In one of the test case I want to wait for 10 mins for a file validation to happen. Global setting for all tests is defined like below:

const config: PlaywrightTestConfig = {
  // Timeout for each Playwright action in milliseconds. Defaults to 0 (no timeout)
  timeout: 120000
  ...
}

I tried these ways:

  1. click({ timeout: 600000 });
  2. test.slow();
  3. test.setTimeout(600000);
  4. page.setDefaultTimeout(600000);
  5. page.setDefaultNavigationTimeout(600000);

In all these cases, the test timesout after 2 mins instead of the overwrite 10 mins(600000).

Bumping up the global setting might work, but it will make the whole test suite run slower which is not ideal.

Is it possible to have timeout for a step be more than the global timeout?


Solution

  • Have custom timeout on specific action:

    Specific action inside Page Object :

     async performSomeAction() {
      //some test steps
       await page.click(someLocator)
       await page.waitForSelector(locatorWhichAppearAfterClick,{timeout:400000})
      //some other steps
    }
    

    Inside Test:

    test('Perform someAction', async () => {
        await page.performSomeAction()  
      },600000)
    

    Reference: https://playwright.dev/docs/test-timeouts