宁静黄瓜-确保元素在视口中



在Serenity Cucumber中,有些方法不会将元素滚动到视图端口中:例如,getValue((方法只会获取该值,而不会滚动浏览器以使元素处于视图中,这会导致报告只显示页面顶部的屏幕截图,而不会显示正在交互的元素。

当前方法示例:

@Step("read first name")
public String readFirstName() {
return $(ContactPage.firstNameField).getValue();
}

我尝试将元素滚动到视图中的示例,因此它显示在屏幕截图上:

@Step("read first name")
public String readFirstName() {
new ScrollToBy(ContactPage.firstNameField).andAlignToTop();
return $(ContactPage.firstNameField).getValue();
}

您可以使用类似剧本模式的问题/任务来阅读屏幕外的文本。


@Subject("the displayed text")
public class TextValue implements Question<String> {
private Target target
@Override
public String answeredBy(Actor actor) {
return target.resolveFor(actor).getText();
}
private TextValue(Target target) {
this.target = target;
}
public static Question<String> of(Target target) { return new TextValue(target); }
}

然后在你的步伐中。。。

theActorInTheSpotlight().wasAbleTo(Scroll.to(ContactPage.firstNameField));
theActorInTheSpotlight().should(eventually(
seeThat(the(TextValue.of(ContactPage.firstNameField)), 
isEqualTo(expectedValue))
));

最新更新