nhungpham1512 / automation_testing_beginner

automation testing course aLinh
0 stars 0 forks source link

Actions #18

Open jacobvn84 opened 1 year ago

jacobvn84 commented 1 year ago

The user-facing API for emulating complex user gestures. Use this class rather than using the Keyboard or Mouse directly. Implements the builder pattern: Builds a CompositeAction containing all actions specified by the method calls.


import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Interaction;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Tasks;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.targets.Target;
import net.thucydides.core.annotations.Step;

public class Tap implements Interaction {

    private Target target;

    public Tap(Target target) {
        this.target = target;
    }

    public static Performable on(Target target) {
        return Tasks.instrumented(Tap.class, target);
    }

    @Override
    @Step("{0} taps on #target")
    public <T extends Actor> void performAs(T theUser) {
        BrowseTheWeb.as(theUser).withAction()
                .click(target.resolveFor(theUser))
                .release().build().perform();
    }
}