playwright-python icon indicating copy to clipboard operation
playwright-python copied to clipboard

[Feature]: Assertions custom message function support

Open infime opened this issue 1 year ago • 0 comments

🚀 Feature Request

expect can take a custom message to display if the assertion fails. Would like the ability to optionally provide a function to construct and return the message.

Example

async def mesg(loc):
  # create a useful error message based on the locator.
  
  return fancy_message

await expect(loc, message=mesg)

Motivation

In cases where additional context is useful to explain the assertion failure, being able to construct this dynamically based on the locator in question would be useful.

Constructing the failure message beforehand isn't feasible since the locators may have changed while waiting.

infime avatar Jun 20 '24 14:06 infime