Serenity BDD Automation Framework

In this tutorial, we will look at the key components of Serenity BDD Automation framework. There are many components that make up an automation project. Let’s touch upon some of the key components.

Sample Project Structure

serenity-jbehave-project

+ pom.xml
+ src
+ main
+ java
+ com
+ testingdocs
+ serenity
+ automationProject
+ pages
+ steps
+ AcceptanceTestSuite.java
+ resources                 ————  configuration files and
.propertiesfiles
+ stories         ———— textual .story file stories
+ storyData     ———— any story data used in the stories.

+ drivers     ————— browser web driver .exe’s

 

 

Key components

Steps are java classes where a JBehave step is implemented for a human-readable textual Gherkin. Using Serenity BDD Framework, tests are broken into reusable steps. It is not necessary to create a new step class when you are creating a story. So, there isn’t any relation between stories and step classes.

 

Sample Story narrative format:

Narrative:
As a Customer <User>
I want to <perform task>
In order to <achieve goal / benefit>

Note that BDD encourages us to put as much information in the stories.

Sample PageObject

PageObject is a way of abstracting or isolating the implementation details of a webpage inside a java class. They are several ways to design Page objects are only concerned with the business logic related to that webpage. Any page object class that we design might need to extend Serenity Page Object. If you do so, Serenity provides a number of utility methods that make page objects more convenient to work with. PageObjects make the web tests much more maintainable.

 

@DefaultUrl("http://www.google.com")
public class GooglePage extends PageObject {
@FindBy(name="q")
WebElement search;
@FindBy(name="btnK")
private WebElement searchButton;
public void enterSearch(String keyword) {
search.type(keyword);
}
public void buttonClick() {
searchButton.click();
}
public void searchFor(String keywords) {
search.sendKeys(keywords, Keys.ENTER);
waitFor(titleContains("Google Search"));
}
}

Serenity BDD Automation Framework

Tools required for building a serenity bdd automation framework are as follows:

JDK
IDE – Eclipse, IntelliJ etc.
Build Tool – Maven , Gradle etc.
Libraries – Serenity, JBehave , Selenium WebDriver etc.
Source control – Git , Subversion etc.
Drivers – GeckoDriver , ChromeDriver etc.

Extras:
CI – Jenkins
Cloud providers – SuaceLabs, BrowserStack etc.

 

Links:

Some useful links are listed below:

Automation Environment Setup

JBehave Framework

Writing Stories

PageObject