net.serenitybdd.screenplay.playwright.interactions.WaitFor Maven / Gradle / Ivy
package net.serenitybdd.screenplay.playwright.interactions;
import com.microsoft.playwright.ElementHandle;
import com.microsoft.playwright.Page;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.playwright.Target;
import net.serenitybdd.screenplay.playwright.abilities.BrowseTheWebWithPlaywright;
import net.serenitybdd.annotations.Step;
import java.util.function.Consumer;
/**
* Wait for some element or state.
*
* Sample usage:
*
* WaitFor.selector("#searchbutton");
*
*/
public class WaitFor implements Performable {
/**
* Default constructor required by Screenplay
*/
public WaitFor() {
}
private Target target;
private Page.WaitForSelectorOptions options;
Consumer nextAction;
public WaitFor(Target target) {
this.target = target;
}
public static WaitFor selector(String selector) {
return new WaitFor(Target.the(selector).locatedBy(selector));
}
/**
* Wait for an element to be in a given state.
*/
public static WaitFor selector(Target target) {
return new WaitFor(target);
}
public WaitFor withOptions(Page.WaitForSelectorOptions options) {
this.options = options;
return this;
}
@Override
@Step("{0} waits for #target")
public void performAs(T actor) {
ElementHandle resolvedElement = BrowseTheWebWithPlaywright.as(actor).getCurrentPage().waitForSelector(target.asSelector(), options);
if (nextAction != null) {
nextAction.accept(resolvedElement);
}
}
public Performable andThen(Consumer nextAction) {
this.nextAction = nextAction;
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy