Is there a way to add a screenshot in this Assert method? When my softAssert fails, I need it to take a screenshot here.

Method of Assert.class :

static public void fail(String message) {
    throw new AssertionError(message);

As you can see, it is static so I cannot override it.

1 Answer 1


One cannot override static methods, more details here. Nonetheless, you can still call it from subclasses, but with a different method (different name or arguments).

class AssertWithScreenhot extends Assert {

  public void failWithScreenshot(String message) {
  • can you please elaborate on your answer or just an example if possible if not it s fine
    – Yan
    Nov 23, 2021 at 11:28
  • I've added an toy-example. Nov 23, 2021 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.