playwright: [Question] is there a way to take screenshots at the exact moment of the failure?
Playwright supports the ability to take screenshots on failed tests: https://playwright.dev/docs/test-configuration#automatic-screenshots.
However, we need to take screenshots at the exact moment of the failure and not after the test cycle. The reason is that we have afterEach/ afterAll hooks that change the states of the page, and after their execution, the issue is no longer visible.
Is there a way to achieve this, or can it be added as a new feature?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 30
- Comments: 15 (3 by maintainers)
For anyone looking for a screenshot solution (might not be exact moment of failure), Playwright offers a
screenshotoption that can be set under theuse: { ... }section in theconfig.tsYou can make it two lines per test file 😃
There is nothing built-in for this. However, it is easy to write an
afterEachhook that does this. Just make sure to put this hook before all other hooks.is there a way to take a fullPage screenshot while using
?
Hello, I apologize in advance if my question is not related to this topic. What if all my test assertions are expect.soft, and when one of them fails the execution continues and the screenshot is taken at the end, thus that is not a fail but just a screenshot of the last action. How can I get exact screenshot on failure in this case?
@cj-larsen this is what the author doesn’t want - it makes the screen at the very end, not the exact fail moment
@watson28 It makes sense, but is a bit more nuanced. For example, if failure happens during the
afterEachhook, then we should probably screenshot at that moment. I’ll see what we can do.Hi! ✌️ @dgozman
Sorry, but I don’t understand why you can not do a screenshot on the
expect.softas like on theexpectfailure. I think it is the main feature for the fast and fulfilment testing Maybe you can advise another realization for configureexpect.soft(maybe create a custom assertion) to solve this significant omission?hi , i also have same issue as arsenpapoyan described above. We cannot leverage .soft in our tests coz of screenshots not being able to be taken at that exact failing moment. Any solutions will be appreciated
thanks for the workaround!
but is there a particular reason for the current behavior? for me, the screenshot option
only-on-failurewill make more sense to work at the exact moment of the failure and not afterward. I feel that should be the default behavior or at least supported as a new option. That will avoid those conflicts of not being able to take the screenshot of the failure if you have defined after* hooks.