Tutorial on Cucumber and Serenity

855 views
Skip to first unread message

Jeff Nyman

unread,
Jul 9, 2016, 9:34:38 AM7/9/16
to Serenity BDD Users Group
For anyone interested, I've completed a three-part post on Serenity and Cucumber:


I should note that I try to contrast a "pull English down" vs "push English up" approach. I think this is actually one of the more interesting avenues of exploration that I've seen Serenity makes possible. I've found this can lead to very productive discussions around the construction of automation, but particularly when you want that automation to be reflective of business-oriented, product-focused, design-guiding discussions.

Putting my cards on the table, I'm not a huge Cucumber fan. (I used to be more open to it; but I find I'm leaning more and more away from it as time goes on.) That said, I think the posts do a fairly good job of simply presenting how Cucumber and Serenity integrate together. My hope is that the posts also, by the end, allow people to consider the appropriate use of abstraction layers. This is something I plan to explore further.

Aleksandr Hlapov

unread,
Jul 14, 2016, 9:00:36 AM7/14/16
to Serenity BDD Users Group
looks like this links available not from everywhere. At least from Ukraine, with out proxy i got request timed out error.

Jeff Nyman

unread,
Jul 14, 2016, 10:16:34 AM7/14/16
to Serenity BDD Users Group

On Thursday, July 14, 2016 at 8:00:36 AM UTC-5, Aleksandr Hlapov wrote:
looks like this links available not from everywhere. At least from Ukraine, with out proxy i got request timed out error.


Hmm. I'm not sure why that would be. The site is definitely up and functioning. I don't think the hosting provider is doing anything that would lead to this. I'll check my htaccess and a few other things.

Thank you for bringing this to my attention.

Joe Colantonio

unread,
Jul 15, 2016, 11:33:48 AM7/15/16
to Serenity BDD Users Group
I'm able to get to the links. Great post Jeff!!!

Matthew Chan

unread,
Jul 28, 2016, 9:55:39 PM7/28/16
to Serenity BDD Users Group
Hi, had a quick read and looks like a good guide to get started into Cucumber-jvm and Serenity-bdd frameworks.

Just have a few comments regarding it, and wondering if you agree/disagree and open to your thoughts as I've previously implemented them into a project to test a responsive web-app.

The examples on the serenity-bdd website for using the two frameworks weren't very clear on how to use them together, and it seemed like the cucumber step definition classes did absolutely nothing, but call serenity step library class methods, which also did nothing as they would again delegate to the page object classes.

What I did instead, was have a step definition which was more high level that contained NO test logic/assertion code, instead delegate it to the serenity step library class methods, whereby all the test code would reside. It would directly call a public WebElementFacade member in the Page Object classes. These page objects would ONLY contain the WebElementFacade elements that are determined by the Serenity @FindBy annotation, and would only contain methods in the case of more complex situations, such as returning values from a dynamic table element etc. 

So the flow would be
Feature file --> Cucumber Step Definitions (Delegates method to Serenity step library, ONLY logic implemented here would be to determine which serenity step library method to call) --> Serenity step library method (Core test code) --> Page object (Only contains WebElementFacade members). 

An more detailed example

Feature file: Update Bank Details
Given I am logged in as a member
When I update the bank details
Then It should be updated

Step Definition Class
BankStepDefs.java
@Steps
BankSerenityLib bankSerenityLib;

@When("^(?i)I update the bank details$") 
public void iUpdateTheBankDetails() throws Throwable {
     bankSerenityLib.navigateToBankDetails();
     bankSerenityLib.editWithValidBankDetails();
     bankSerenityLib.validateBankUpdatedSuccessMessage();
}


Serenity Step Library Class
BankSerenityLib.java

NavigationPage navigationPane;
UpdateBankPage updateBankPage;

@Step
public void navigateToBankDetails() {
     navigationPane.bankBtn.click();
     navigationPane.updateBankBtn.waitUntilClickable().click();
     assertThat(updateBankPage.updateBankHeading.isCurrentlyVisible()).isTrue();
}

@Step
public void editWithValidBankDetails() {
     updateBankPage.editBankDetails.click();
     updateBankPage.bsbField.typeAndTab("82424242");
     etcetc.
}


Page Object
UpdateBankPage.java

@FindBy(id = "bsb")
public WebElementFacade bsbField;

@FindBy(id = "acctNo")
public WebElementFacade accountNumField;


I noticed that you didn't use the Serenity WebElementFacade, was there a reason why?

Let me know your thoughts, thanks. 
Reply all
Reply to author
Forward
0 new messages