Alex
Alex

Reputation: 170

Serenity Cucumber - Make sure element is within the viewport

In Serenity Cucumber, some methods do not scroll the element into the view port: for example, the getValue() method will just get that value and not scroll the browser so that the element is in view, which causes the report to just show a screen shot of the top of the page, but not the element that is being interacted with.

Example current method:

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

Example of my attempt(s) to scroll the element into view, so it shows on the screenshot:

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

Upvotes: 0

Views: 1921

Answers (1)

drkstr101
drkstr101

Reputation: 807

You could use something like screenplay pattern questions/tasks for reading off-screen text.


@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); }
}

Then in your steps...

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

Upvotes: 1

Related Questions