All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.simple4tests.webdriver.reporters.ReporterWithErrorHandler Maven / Gradle / Ivy

The newest version!
package io.github.simple4tests.webdriver.reporters;

import java.util.ArrayList;
import java.util.List;

public abstract class ReporterWithErrorHandler implements Reporter {

    List errors = new ArrayList<>();

    public boolean hasErrors() {
        return !errors.isEmpty();
    }

    public void addError(String error) {
        errors.add(error);
    }

    public void clearErrors() {
        errors.clear();
    }

    public String getErrorsSummary() {
        if (hasErrors()) {
            return String.join("\n", errors);
        }
        return "NO ERRORS FOUND, CONGRATULATIONS!";
    }

    public void throwAssertionErrorIfAny(boolean reportErrorsSummary) {
        if (hasErrors()) {
            if (reportErrorsSummary)
                reportAction("Report error(s) summary", getErrorsSummary());
            throw new AssertionError(String.format("%d error(s) found", errors.size()));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy