Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Parametrize expect with soft option #30907

Closed
MartinPilny opened this issue May 20, 2024 · 3 comments
Closed

[Feature]: Parametrize expect with soft option #30907

MartinPilny opened this issue May 20, 2024 · 3 comments

Comments

@MartinPilny
Copy link

馃殌 Feature Request

Currently, in Playwright, to perform a soft assertion, you must explicitly call expect.soft(...).... This approach does not lend itself well to parametrization, as it requires a different method call. I propose adding a soft option directly to the expect function to allow for easier and more flexible parametrization.

Example

Current method (hard to parametrize)

if (isSoftCheck) {
  expect.soft(element).toHaveText('expected text')
} else {
  expect(element).toHaveText('expected text')
}

Proposed method (easily parametrized)

expect(element, { soft: isSoftCheck }).toHaveText('expected text')

Or as chainer method

expect(element)
  .soft(isSoftCheck)
  .toHaveText('expected text')

Motivation

  • Simplified Code: This feature will remove the need for conditional logic around assertions, making tests easier to read and write.
  • Increased Flexibility: It will allow for easier switching between soft and hard assertions based on parameters or configurations.
  • Enhanced Consistency: A consistent approach to assertions will reduce errors and improve maintainability.
@MartinPilny
Copy link
Author

If done properly, this might be solid base for #29465

@pavelfeldman
Copy link
Member

We already have something similar: https://playwright.dev/docs/test-assertions#expectconfigure. For your use case a one-line wrapper should do the trick.

const myexpect = (element, isSoft) => isSoft ? expect.soft(element) : expect(element);

@pavelfeldman
Copy link
Member

Closing as per above, please feel free to open a new issue if this does not cover your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants