Skip to content

[Feature]: Add a timeout message option to locator.waitFor() method#38002

Description

馃殌 Feature Request

When locator.waitFor() do not fulfill the wait and fail we get a fairly generic error message. The error messages usually looks something like this:

 Error: locator.waitFor: Target page, context or browser has been closed
    Call log:
      - waiting for locator('#my_fancy_locator') to be visible
      ...

or

    TimeoutError: locator.waitFor: Timeout 10000ms exceeded.
    Call log:
      - waiting for locator('#my_fancy_locator') to be visible
      ...

Add a message option to waitFor option where we could provide a custom error message.

Example

// some code
// ...
page.locator('#my_fancy_locator').waitFor({ state: 'visible', timeout: 10000, message: 'Fancy Locator never displayed' });

This could produce this failing msg:

    TimeoutError: Fancy Locator never displayed (locator.waitFor: Timeout 10000ms exceeded).
    Call log:
      - waiting for locator('.modal__title-row') to be visible

or we could get a similar error message structure as expects:

TimeoutError: Fancy Locator never displayed

    locator.waitFor() failed

    Locator: locator('#my_fancy_locator')
    Waiting state: visible
    Timeout: 10000ms
    TimeoutError: element(s) not found

    Call log:
      - Fancy Locator never displayed with timeout 10000ms
      - waiting for .locator('#my_fancy_locator')

Motivation

This simple change would improve the error messages and make it easier to see what has failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions