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

net.serenitybdd.screenplay.AnonymousPerformableFunction Maven / Gradle / Ivy

There is a newer version: 4.2.9
Show newest version
package net.serenitybdd.screenplay;

import net.serenitybdd.markers.CanBeSilent;
import net.serenitybdd.annotations.Step;
import net.thucydides.core.steps.StepEventBus;
import net.thucydides.model.steps.ExecutedStepDescription;
import net.thucydides.model.steps.StepFailure;

import java.util.function.Consumer;

public class AnonymousPerformableFunction implements Performable, CanBeSilent {
    private final String title;
    private final Consumer actions;
    private boolean isSilent = false;

    public AnonymousPerformableFunction(String title, Consumer actions) {
        this.title = title;
        this.actions = actions;
    }

    @Override
    @Step("!#title")
    public  void performAs(T actor) {
        try {
            actions.accept(actor);
        } catch (Throwable e) {
            StepEventBus.getEventBus().stepFailed(new StepFailure(ExecutedStepDescription.withTitle(e.getMessage()), e));
            throw e;
        }
    }

    @Override
    public boolean isSilent() {
        return isSilent;
    }

    public AnonymousPerformableFunction withNoReporting() {
        this.isSilent = true;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy