Screenplay - how should I scroll to a position?

2,646 views
Skip to first unread message

Ilyas Patel

unread,
Jul 13, 2016, 1:14:13 PM7/13/16
to Serenity BDD Users Group
Just wanted to get some thoughts on my first screenplay test. The test is mainly just checking certain elements in various pages are displayed as they rely on a new type of authentication.

To check certain elements exist, I wanted to scroll to the element (probably using JavaScript) and I'm not quite sure where I should do this. I've put an example below of where I think it might go but then I'm exposing UI elements in the test.


@Test
public void items_related_to_login_should_be_displayed() {
givenThat(anna).wasAbleTo(Start.onTheSignInPage());

andThat(anna).wasAbleTo(
Login.with("abc", "abc")
);

when(anna).attemptsTo(
openPage1,
Scroll.to(By.className("foo"))
);
then(anna).should(eventually(seeThat(TheWebPage.title(), containsString("some text"))));

when(anna).attemptsTo(
openPage2,
Scroll.to(By.className("foo"))
);
then(anna).should(eventually(seeThat(TheWebPage.title(), containsString("some text"))));
}
Message has been deleted

Harry King

unread,
Jul 14, 2016, 11:12:26 AM7/14/16
to Serenity BDD Users Group
Not sure how it works with screenplay, but you can use the Actions class in Selenium to scroll to a WebElement.

WebElement login = element(By.cssSelector("#login"));
new Actions(getDriver()).moveToElement(login).build().perform();

Ilyas Patel

unread,
Jul 15, 2016, 10:49:24 AM7/15/16
to Serenity BDD Users Group
Thanks Harry.

I suppose I was wondering what would be the correct way to do it in the screenplay pattern. What I've done is added the Scroll.to() action in my Question class as this is where I was interested in the particular bit of data I was after:

public class TheWatchedHistory implements Question<String> {

@Override
public String answeredBy(Actor actor) {
Scroll.to(WatchedHistoryItem.HEADING).performAs(actor);

return Text.of(WatchedHistoryItem.HEADING).viewedBy(actor).asString();
}

public static Question<? extends String> text() {
return new TheWatchedHistory();
}
}

John Smart

unread,
Jul 15, 2016, 11:24:49 AM7/15/16
to Ilyas Patel, Serenity BDD Users Group

Hi Ilyas,

To scroll to a point, you would just invoke the Scroll class, e.g.

    actor.attemptsTo(Scroll.to(WatchedHistoryItem.HEADING))

You wouldn’t normally call the performAs() method directly. 

It would also be unusual to perform an action inside a Question (Questions are meant to be read-only and as idempotent as possible). 

I assume it’s because you are experimenting, but the code in the test does look quite low level - normally you wouldn’t have UI interactions directly at the test level when you use the ScreenPlay pattern; rather the test would only contain business tasks that describe what the user is doing in business terms, not in terms of UI interactions. 

It would also be unusual to have "when..then..when..then", as ScreenPlay encourages tests to describe the behaviour and expected outcome of a single acceptance criteria in each test (like well-written BDD scenarios). So the scenario might look something like this:

        givenThat(anna).wasAbleTo(LoginToTheApplication.asANormalCustomer());

    when(anna).attemptsTo(

        ViewTheCatologItems.forCategory(“foo”)

    );

    then(anna).should(eventually(seeThat(TheCatalog.title(), containsString("All Things Foo"))));

}


--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +44 7398 832273
Making smart teams collaborate better
http://johnfergusonsmart.com  |  john....@wakaleo.com
___________________________________________________

We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Product Planning, BDD Requirements Discovery,  BDD, TDD and Clean Coding, and Advanced BDD Test Automation.
___________________________________________________
Reply all
Reply to author
Forward
0 new messages