-
|
So as simple as that, can't figure out how to take screenshot at the moment of soft assert failure instead of at the end of test, Using testNg btw |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
@borzykin not sure how much help this will be, but you could potentially use a custom soft assertion provider that just delegates to the default provider implementation. In this provider, you may be able to try-catch any AssertionError and use java.awt.Robot to capture the primary display device to a BufferedImage. I have not used TestNG but you may be able to find a way to infer the test name (maybe by walking the stack trace of the thread), to get a meaningful file name for the image to save. If you didn't need it for the specific assertion, but just the final assertion error that is thrown, you could just have a lambda that wraps your test case and catches an AssertionError, takes the screenshot using robot, and then rethrows the error again. |
Beta Was this translation helpful? Give feedback.
-
|
There are two options:
Both ways allow you to provide your own logic to be executed with each assertion error. You can find examples about both solutions in the AssertJ documentation. |
Beta Was this translation helpful? Give feedback.
There are two options:
setAfterAssertionErrorCollectedon yourSoftAssertionsinstance, providing your ownAfterAssertionErrorCollectedimplementation (can be a lambda).AbstractSoftAssertionsand overrrideonAssertionErrorCollected.Both ways allow you to provide your own logic to be executed with each assertion error.
You can find examples about both solutions in the AssertJ documentation.
Related: https://stackoverflow.com/questions/68510688