Skip to main content

Posts

Showing posts with the label SoftAssert

Soft Assertions: Where and when we can use it?

To tackle the disadvantage of Hard Assertions where we want to continue the execution even if some assert fails and see the result at the end of the test. Soft Assertions are the type of assertions that do not throw an exception when an assertion fails and continue with the next step after assert statement. This is in the case where our test requires multiple assertions to be executed and we want all of the assertions to be executed first before marking (failing/skipping) the tests. Consider these 2 examples: 1) We're verifying many CSS values of the same element like background-color, font-family, and color in a single test case. element.getAttribute("background-color") element.getCssValue("font-family") element.getCssValue("color") Obviously, if any one of these fails we would like to catch it and mark the test case as fail but that doesn't mean if background-color verification fails it should mark the test case fail with