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

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

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

import net.serenitybdd.core.pages.WebElementFacade;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.targets.Target;
import org.openqa.selenium.By;

import java.util.function.Consumer;

public class PerformOn implements Performable {
    private final Target target;
    private final Consumer action;

    public PerformOn(String xpathOrCssLocator, Consumer action) {
        this.target = Target.the(xpathOrCssLocator).locatedBy(xpathOrCssLocator);
        this.action = action;
    }

    public PerformOn(Target target, Consumer action) {
        this.target = target;
        this.action = action;
    }

    @Override
    public  void performAs(T actor) {
        target.resolveAllFor(actor).forEach(action);
    }

    public static Performable eachMatching(Target target, Consumer action) {
        return new PerformOn(target, action);
    }

    public static Performable eachMatching(By byLocator, Consumer action) {
        return eachMatching(Target.the(byLocator.toString()).located(byLocator), action);
    }

    public static Performable eachMatching(String locator, Consumer action) {
        return eachMatching(Target.the(locator).locatedBy(locator), action);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy