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

net.serenitybdd.screenplay.actions.ChainablePerformable Maven / Gradle / Ivy

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

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import org.openqa.selenium.interactions.Actions;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public abstract class ChainablePerformable implements WithChainableActions {

    private List> actionsToPerform = new ArrayList<>();

    protected ChainablePerformable() {}

    protected void addAction(Consumer action) {
        actionsToPerform.add(action);
    }

    protected void addActionAtStart(Consumer action) {
        actionsToPerform.add(0,action);
    }

    public WithChainableActions andThen(Consumer nextAction) {
        actionsToPerform.add(nextAction);
        return this;
    }

    public  void performSubsequentActionsAs(Actor actor) {
        Actions browserActions = BrowseTheWeb.as(actor).withAction();
        actionsToPerform.forEach(
                action -> action.accept(browserActions)
        );
        browserActions.build().perform();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy