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

net.serenitybdd.screenplay.actions.AlertAction 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.Performable;
import net.serenitybdd.screenplay.Question;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;

/**
 * Switch to an alert window
 */
public class AlertAction implements Performable {
    @Override
    public  void performAs(T actor) {
        BrowseTheWeb.as(actor).getDriver().switchTo().alert();
    }

    /**
     * Dismiss the HTML alert message
     */
    public Performable andDismiss() {
        return Task.where("{0} dismisses the alert dialog",
                actor -> BrowseTheWeb.as(actor).getDriver().switchTo().alert().dismiss()
        );
    }

    /**
     * Accept the HTML alert message
     */
    public Performable andAccept() {
        return Task.where("{0} accepts the alert dialog",
                actor -> BrowseTheWeb.as(actor).getDriver().switchTo().alert().accept()
        );
    }

    /**
     * Retrieve the text of the current alert window
     */
    public Question getText() {
        return Question.about("the alert text")
                .answeredBy(actor -> BrowseTheWeb.as(actor).getDriver().switchTo().alert().getText());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy