net.serenitybdd.screenplay.questions.TheSize Maven / Gradle / Ivy
package net.serenitybdd.screenplay.questions;
import net.serenitybdd.core.pages.WebElementFacade;
import net.serenitybdd.screenplay.Question;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.targets.Target;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.Collections.singletonList;
/**
* What is the width and height of the rendered element?
*/
public class TheSize {
public static Question of(Target target) {
return Question.about("size of " + target.getName()).answeredBy(actor -> matches(target.resolveAllFor(actor)));
}
public static Question of(By byLocator) {
return Question.about("size of element located by " + byLocator).answeredBy(actor -> matches(BrowseTheWeb.as(actor).findAll(byLocator)));
}
public static Question of(String locator) {
return Question.about("size of " + locator).answeredBy(actor -> matches(BrowseTheWeb.as(actor).findAll(locator)));
}
public static Question> ofEach(Target target) {
return Question.about("size of each of " + target.getName()).answeredBy(actor -> target.resolveAllFor(actor)
.stream()
.map(element -> matches(singletonList(element)))
.collect(Collectors.toList()));
}
public static Question> ofEach(By byLocator) {
return Question.about("size of each of element located by " + byLocator).answeredBy(actor -> BrowseTheWeb.as(actor).findAll(byLocator)
.stream()
.map(element -> matches(singletonList(element)))
.collect(Collectors.toList()));
}
public static Question> ofEach(String locator) {
return Question.about("size of each of " + locator).answeredBy(actor -> BrowseTheWeb.as(actor).findAll(locator)
.stream()
.map(element -> matches(singletonList(element)))
.collect(Collectors.toList()));
}
private static Dimension matches(List elements) {
return elements.stream()
.findFirst()
.map(WebElementFacade::getSize)
.orElse(null);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy