Serenity BDD Framework Overview
Serenity is an open-source reporting library that enables developers to write easily-understandable and better-structured acceptance criteria for test automation projects. In addition to generating meaningful reports for each test, the tool also shows the list of features tested in each test case. With the details of the executed tests and the requirements that were tested, Serenity BDD Framework allows you to better understand how an application works and what it does.
The good thing about Serenity BDD Framework is that it supports multiple automated acceptance testing solutions. You can use the tool along with JUnit to quickly write clean and maintainable acceptable criteria or integrate it with WebDriver to test web applications in Selenium. It also supports RestAssured to test REST API. Serenity allows you to use any Behaviour-driven Development (BDD) tool such as Cucumber. You can also use any test case management tool such as JIRA or choose a directory-based approach.
What is BDD?
BDD stands for Behavior-driven Development. It has actually evolved from Test-driven Development (TDD) that talks about writing the test cases before writing the code. BDD also takes the same approach but focuses on system behavior and user behavior. In a BDD environment, tests are written in shared language so that all stakeholders (technical and non-technical) will be able to understand how an application works. It also facilitates nice collaboration between different teams. The ability to write test cases in a common language such as English gives a big advantage for developers while preparing acceptance testing criteria. You can write test cases depicting real-time scenarios.
History and Main Concepts of BDD
It was Daniel Terhorst-North who pioneered the development of BDD methodology in 2003. Liz Keogh contributed to the concept in 2004 along with Chris Matts and developed the template ‘Given / When / Then’ for capturing user stories and converting them into an executable form. This concept was inspired by the ‘Domain Driven Design’ written by Eric Evans. Another inspiration was taken from the user story template ‘As a / I / So that’ created by Rachel Davies. In 2005, Dave Astels, David Chelimsky, Steven Baker and Aslak Hellesoy founded RSpec Project that supported BDD in Ruby. While improving this project, Aslak came up with a better version of RSpec Story Runner and he named it Cucumber.
In a BDD approach, requirements are converted into user stories and valid user scenarios.
An example of a BDD template is
Another example is
- As a (premium customer)
- I want (to browse the new arrivals in the fashion accessories segment)
- So that (I can order the best apparels)
BDD comes with a minimal learning curve owing to the usage of a shared language. It provides seamless collaboration between different teams. Here, you are defining the behavior and not the test. So, the acceptance criteria is defined before developing the code which is beneficial for business owners as they get a clear understanding of how the application behaves instead of thinking about the features.
Cucumber and Serenity are a couple of popular BDD frameworks.
Getting Started with Serenity BDD Framework
These components run Serenity BDD Framework. They are all required.
- IntelliJ IDE
- Serenity BDD Plugin
Step 1: Install Java
To download Java, visit the following link:
Download the Java Development Kit (JDK)
Java SE 14.0.2 is the latest release for the Java Standard Edition Platform. Accept the license agreement and proceed with the download.
After the software downloads, double-click the application and install Java.
Choose the destination folder and click next.
The setup package installs Java on your machine. Click close to finish the installation.
To check if you successfully installed Java, open the command prompt, and type the version command.
- java -version
Step 2: Configure Environment Variables
To use Java, you should configure environment variables. Add Java path under system variables and user variable settings. To do so,
- Click on System -> Advanced System Settings -> Advanced -> Environment Variables
Check if Java path is added under system variables and user variables path.
Now Java is ready for use.
Step 3: Install IDE
To write and execute tests using Serenity BDD Framework, you need a modern IDE. You can either choose IntelliJ or Eclipse. To install IntelliJ, visit the following website.
Click on the Download button to download the tool. IntelliJ is offered in two versions; Ultimate with a 30-day trial and Community version that is free and open-source. Choose the community version for the test purpose.
Now, double-click the IntelliJ software to being the installation procedure.
Click next and choose the installation location.
The next screen prompts you to customize installation options.
You can create a desktop shortcut or update the context menu. The important feature to note is the ‘Update PATH variable’ option. When you select it, it will automatically configure the environment variables. It means you don’t have to manually add the IntelliJ path to the system variables and user variables.
On the next screen, choose the start menu option and click next to proceed with the installation.
After the installation is completed, it will prompt for a restart. You can choose to manually restart it later.
In the next screen, choose your preference for data sharing.
Now, the IDE opens up.
So, it is ready for use. You can choose the UI version Dracula (in dark mode) or Light (light mode)
Now, the tool is ready. You can choose a new project or open an existing one.
Step 4: Install Gradle
In order to execute tests and generate reports, you should add a built tool such as Maven or Gradle. You can download Maven here:
For Gradle, visit this link:
Create a folder called Gradle in C drive and unzip the Gradle package into that folder.
Step 5: Configure Environment Variable
To use Gradle, you should configure environment variables. Follow the steps mentioned in Step 2 to open the Environment Variables setting. Add the following path under system variables.
To check if Gradle is successfully configured, open a command prompt window and type the version command.
- Gradle -version
So, Gradle is working fine.
Step 6: Add Serenity BDD Plugin
To run your tests using Serenity BDD Framework, you should add the Serenity plugin. To do so, open the IntelliJ IDE.
Click on New Project. On the left side menu, choose Gradle.
Choose a name and the location of the build folder and click finish.
The tool will download the necessary files and create a new Gradle project.
After the build is completed, it will display a message that the build is successful.
Adding Serenity BDD Plugin
To apply the Serenity BDD Framework plugin to the project, open the build.gradle file and edit it with the following code.
Notice that the code mentions serenityVersion. The latest version is 2.2.12. When you run the code, it will install the Serenity plugin 2.2.12.
Along with the Serenity Gradle plugin, it will install all the dependencies. In this example, the Junit testing library is added. You can choose any other test library as well and add it under dependencies.
Now, open the command prompt window and type the following command.
- Gradle test aggregate
The build is successful. The test reports are stored in the root folder – C:ExperitestSerenitytargetsiteserenity. When you open the index HTML file, you can check the test reports generated by Serenity BDD Framework. As we have added the continueOnFailure, the tests will continue even though some tests fail.
Running Your First Test
Here is a sample test using a demo site http://decohere.herokuapp.com. This project authenticates a user login task and checks if the user is able to log in and navigate to the welcome page.
Open your project ExperitestSerenity in the IntelliJ IDE.
Here is a list of packages and classes created for the project.
This is the main class that checks if the user is on the Home Page, logins to the account as an admin and successfully navigates to the welcome page.
This class provides the Home page details for the main class.
This class provides the username and password to login to the site.
This class shows the welcome page message.
When you run the test in IntelliJ IDE, it will open the Decohere home page and signs-in to the account. The Serenity BDD will generate a report with the test details.
Serenity BDD Framework’s handy reporting library lets you run better structured and easier to understand acceptance tests. With reports getting generated for each action at every step, developers can understand how each feature is working and quickly identify errors. Serenity Step Libraries enable you to annotate methods with @Step annotation so that you can orchestrate calls to different layers such as databases, web services, and page objects. Overall, Serenity BDD Framework is a good choice when it comes to acceptance testing.
Continuous Testing is about breaking down barriers. See how important continuous testing in the cloud remains in 2021 with this webinar video.
What's New In The World of Digital.ai
Digital.ai Continuous Testing, First in Market to Support Android 14 DP
Digital.ai is proud to announce that our Continuous Testing solution is the first in the market to support testing on Android 14 (Developer Preview). Read on to learn more!
Who Is In Charge? How to Eliminate Gatekeeping and Boost Quality
Often, a gatekeeper is solely responsible for software quality. But by dividing QA amongst the whole development team, the workload will be spread evenly allowing for fewer bottlenecks and delays in production.
Scaled Mobile App Testing Approach with Digital.ai Continuous Testing
Security starts with a comprehensive mobile app testing approach that includes critical elements of security as well as function and UX. Read on to learn more!