question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] WaitFor timeout doesn't work, if it bigger than default global timeout

See original GitHub issue

Context:

  • Playwright Version: 1.25.2
  • Operating System: Linux
  • Node.js version: v16.14.0
  • Browser: Chromium, WebKit
  • Extra: Headless and headed mode

Code Snippet

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

test(`test waiting top limit`, async ({page}) => {
    await page.goto('https://playwright.dev/docs/actionability');
    await page.locator('.search123').waitFor({state: "visible", timeout: 60000})
});

Describe the bug

playwright.config.ts doesn’t have any timeout options, so default 30 seconds are taken. When I’m setting up a bigger timeout than the default for a single action, the test above waits for 30 seconds instead of the expected 60.

Running 1 test using 1 worker
  1) [webkit] › tests/testwaitings.spec.ts:3:1 › test waiting top limit ============================

    Test timeout of 30000ms exceeded.

    locator.waitFor: Target closed
    =========================== logs ===========================
    waiting for selector ".search123" to be visible
    ============================================================

      3 | test(`test waiting top limit`, async ({page}) => {
      4 |     await page.goto('https://playwright.dev/docs/actionability');
    > 5 |     await page.locator('.search123').waitFor({state: "visible", timeout: 60000})
        |                                      ^
      6 | });
      7 |

        at file:///Projects/playwright-tests/tests/testwaitings.spec.ts:5:38

    Pending operations:
      - locator.waitFor at tests/testwaitings.spec.ts:5:38

Additional info:

Debug mode doesn’t have above issue. When running the test with PWDEBUG=1, it waits for 60 seconds.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mila-qacommented, Sep 15, 2022

If a function has an option to set maximum timeout it’s logical to be able to use it.

  /**
   * Returns when element specified by locator satisfies the `state` option.
   *
   * If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to `timeout`
   * milliseconds until the condition is met.
   *
   * ```js
   * const orderSent = page.locator('#order-sent');
   * await orderSent.waitFor();
   * ```
   *
   * @param options
   */
  waitFor(options?: {
    /**
     * Defaults to `'visible'`. Can be either:
     * - `'attached'` - wait for element to be present in DOM.
     * - `'detached'` - wait for element to not be present in DOM.
     * - `'visible'` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element without
     *   any content or with `display:none` has an empty bounding box and is not considered visible.
     * - `'hidden'` - wait for element to be either detached from DOM, or have an empty bounding box or `visibility:hidden`.
     *   This is opposite to the `'visible'` option.
     */
    state?: "attached"|"detached"|"visible"|"hidden";

    /**
     * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
     * using the
     * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout)
     * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#page-set-default-timeout) methods.
     */
    timeout?: number;
  }): Promise<void>;}

Unfortunately, it’s not possible with the current implementation. Decreasing the waiting time doesn’t have logical sense, because If target element already satisfies the condition, the method returns immediately.

Anyway, thanks for the suggested workarounds.

0reactions
mxschmittcommented, Sep 15, 2022

I’m looking for a solution for one action in a test.

This is an unsolvable problem, because the scopes are different, one per whole test execution and one for a single statement.

Unfortunately this is not a valid feature request, since this is working as expected and changes to the behaviour would not make logical sense.

So to recap, either increase test timeout for all the tests, use test.slow()/setTimeout for a single test or decrease the waiting time of waitFor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exceeded timeout of 5000 ms for a test · Issue #11607 - GitHub
I have started getting this issue: thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout ...
Read more >
Message "Async callback was not invoked within the 5000 ms ...
The default timeout value is 5000 (5000 ms - 5 seconds). This will be applicable for all test cases. Or if you want...
Read more >
Async Methods - Testing Library
The default timeout is 1000ms . The default onTimeout takes the error and appends the container 's printed state to the error message...
Read more >
Tip: change default timeout of `waitFor` in React Testing Library
In React Testing Library, there is no global configuration to change default timeout of waitFor , but we can easily wrap this function...
Read more >
Troubleshoot query time-out errors - SQL Server
Assume that an application queries data from a SQL Server database. If the query doesn't return any data within the configured time-out ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found