Screenplay Pattern: Using NamedUrls with the Serenity Open action

251 views
Skip to first unread message

Opal

unread,
Mar 23, 2017, 10:19:06 AM3/23/17
to Serenity BDD Users Group
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?

John Smart

unread,
Mar 23, 2017, 10:21:25 AM3/23/17
to Opal, Serenity BDD Users Group
targetPage could be made protected, it doesn't really need to be private.

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to thucydides-users@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.

Need some help with Serenity BDD? Check out our Serenity BDD training and support packages here.
___________________________________________________

Opal

unread,
Mar 23, 2017, 10:34:48 AM3/23/17
to Serenity BDD Users Group, j.opa...@gmail.com
Thanks!  That was sort of a parenthetical comment intended to justify my shortcut in demonstrating my proposed solution. Any thoughts on whether this is generally the right way to solve this particular puzzle?
Reply all
Reply to author
Forward
0 new messages