I am building an automated framework based on the Screenplay Pattern using Serenity.
One of the central pages in our application is accessed via a query string, and none of the methods of the net.serenitybdd.screenplay.actions.Open class take any parameters that could allow for the use of the @NamedUrls for the page in question.
The best solution that I can see is to extend the OpenPage action to add a method to allow the addition of a namedUrl and a set of parameters to be passes to the PageObject.open() method.
Ex:
public class OpenPageWithQuery extends OpenPage {
private String namedUrl = null;
private String[] parms = new String[0];
public OpenPageWithQuery(PageObject targetPage) {
super(targetPage);
}
@Step("{0} opens the #targetPage")
public <T extends Actor> void performAs(T theUser) {
if(this.namedUrl== null){
super.performAs(theUser);
} else {
this.targetPage.setDriver(BrowseTheWeb.as(theUser).getDriver());
this.targetPage.open(this.namedUrl, this.parms);
}
}
public OpenPageWithQuery withNamedUrl(String targetNamedUrl, String... parameterValues) {
this.namedUrl = targetNamedUrl;
this.parms = parameterValues;
return this;
}
}
Except, of course, I can't quite do it that way because targetPage is private in the parent class, so I'd probably just end up re-implementing the parent class (which seems a little clunky to me but I'm willing to accept it as a price of using all the other useful parts of the framework...)
Has anyone else run into this puzzle? Is there a better way?