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

net.serenitybdd.screenplay.targets.EnsureFieldVisible Maven / Gradle / Ivy

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

import net.serenitybdd.core.pages.WebElementFacade;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.actions.Scroll;
import org.openqa.selenium.WebDriverException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EnsureFieldVisible {
    private final Actor actor;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public static EnsureFieldVisible ensureThat(Actor actor) {
        return new EnsureFieldVisible(actor);
    }

    private EnsureFieldVisible(Actor actor) {
        this.actor = actor;
    }

    public void canSee(WebElementFacade targetElement) {
        if ((targetElement != null) && (!targetElement.isCurrentlyVisible())) {
            try {
                actor.attemptsTo(Scroll.to(targetElement));
            } catch (WebDriverException failedToMoveToElement) {
                logger.warn("Failed to move to target", failedToMoveToElement);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy