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

net.serenitybdd.screenplay.waits.WaitUntilExpectation Maven / Gradle / Ivy

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

import net.serenitybdd.markers.IsSilent;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Interaction;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.thucydides.core.steps.StepEventBus;
import net.thucydides.model.environment.SystemEnvironmentVariables;
import org.openqa.selenium.support.ui.ExpectedCondition;

import java.time.Duration;

import static net.thucydides.model.ThucydidesSystemProperty.WEBDRIVER_WAIT_FOR_TIMEOUT;

public class WaitUntilExpectation implements Interaction, IsSilent {

    private final ExpectedCondition expectedCondition;
    private Duration duration;

    public WaitUntilExpectation(ExpectedCondition expectedCondition) {
        this.expectedCondition = expectedCondition;
        int durationInMillis = SystemEnvironmentVariables.currentEnvironmentVariables().getPropertyAsInteger(WEBDRIVER_WAIT_FOR_TIMEOUT, 3000);
        this.duration = Duration.ofMillis(durationInMillis);
    }

    @Override
    public  void performAs(A actor) {
        BrowseTheWeb.as(actor).withTimeoutOf(duration).waitFor(expectedCondition);

    }

    public Interaction forNoMoreThan(Duration duration) {
        this.duration = duration;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy