vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Playwright locator timeout is too high

Open julienw opened this issue 1 month ago • 6 comments

Describe the bug

From what I see, the timeout I get when a locator doesn't match is 30 seconds, which is a lot.

As a reference, the default timeout in playwright itself seems to be 15 sec, and when using the webdriver.io provider, it seems to be reduced to 5 seconds which seems good enough to me.

Also I couldn't find the place to configure it.

Reproduction

Please tell me if you need a reproduction for this.

System Info

System:
    OS: Linux 6.7 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz
    Memory: 36.15 GB / 62.54 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 24.8.0 - /home/julien/.nvm/versions/node/v24.8.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 11.6.0 - /home/julien/.nvm/versions/node/v24.8.0/bin/npm
    pnpm: 10.9.0 - /home/julien/.local/share/pnpm/pnpm
    bun: 1.0.29 - /home/julien/.bun/bin/bun
    Deno: 2.0.0 - /home/julien/.cargo/bin/deno
    Watchman: 4.9.0 - /usr/bin/watchman
  Browsers:
    Chrome: 142.0.7444.175
    Chromium: 142.0.7444.175
    Firefox: 140.5.0esr
    Firefox Developer Edition: 140.5.0esr
  npmPackages:
    @vitest/browser: ^4.0.14 => 4.0.14 
    @vitest/browser-playwright: ^4.0.14 => 4.0.14 
    vitest: ^4.0.14 => 4.0.14

Used Package Manager

npm

Validations

julienw avatar Dec 02 '25 16:12 julienw

Playwright locators don't actually have a timeout. They timeout when the test timeouts (this is also how it works in playwright). Default timeout for tests is 30 seconds in browser mode. Funnily enough, the docs are wrong about the number which was 15 at one point: https://vitest.dev/config/testtimeout.html

Seems like it was changed in https://github.com/vitest-dev/vitest/pull/8705 - maybe by accident?

sheremet-va avatar Dec 02 '25 16:12 sheremet-va

Ah interesting, I thought the matcher was producing the error because the error string isn't a generic one like "test timeout" but rather:

VitestBrowserElementError: Cannot find element with locator: getByRole('heading', { name: 'Usrs', level: 1 })
...
Caused by: Error: Matcher did not succeed in time.

julienw avatar Dec 02 '25 16:12 julienw

Yes, it's done for better DX. The timeout itself is dynamic and based on the time left until the test timeout

sheremet-va avatar Dec 02 '25 16:12 sheremet-va

So to configure it you can change the testTimeout value or set a static value via actionTimeout:

export default defineConfig({
  test: {
    testTimeout: 15_000,
    browser: {
      provider: playwright({ actionTimeout: 5_000 }),
    },
  },
})

sheremet-va avatar Dec 02 '25 16:12 sheremet-va

Thanks! I tried adding actionTimeout: 5_000, but it seems to be about 2 seconds, no matter the value I use... Isn't it weird?

julienw avatar Dec 03 '25 15:12 julienw

Seems like it was changed in #8705 - maybe by accident?

Yes, this seems like a rebase/merge conflict mistake. Not intended.

AriPerkkio avatar Dec 04 '25 05:12 AriPerkkio