Open heathiviesyncro opened 2 years ago
Any idea how to implement this now? Try/Except with short timeout or is there a better way?
I am using pytest-check
for soft assertions. Adds another dependency to the project, but it works great.
I am using
pytest-check
for soft assertions. Adds another dependency to the project, but it works great.
I tried this one but couldn't get it working with expect(). Do you have an example of this?
Also +1 for soft assertions to be implemented in python as well as typescript.
I tried this one but couldn't get it working with expect(). Do you have an example of this?
It's a separate assertion mechanism, so you don't use it within expect()
. Pretty nice examples are included on the github page: https://github.com/okken/pytest-check
Also - you can mix assertions in your tests, so it's fine to use assert
, expect()
and check()
.
I agree, it would be really useful to have soft assertions in Python version of Playwright. Right now I'm using workarounds in some of my projects, similar to what was already mentioned above.
I spent some time exploring the code and came up with an approach that seems to work. Here’s an example of how it looks:
def test_foo(page: Page) -> None:
# ...
with soft_assertions() as expect:
expect(page.locator("div")).to_have_text("foo")
expect(page.locator("div")).to_have_text("bar")
expect
in this example works just like a normal expect
(works with pages, locators and api responses).
At first, I considered an expect.soft(...)
approach like in Node, but I couldn’t find a solution that didn’t require a lot of changes.
Would love any feedback on this!
It would be nice to get the soft assertions that are available in node to be available in python.
https://playwright.dev/docs/test-assertions#soft-assertions
Thank you