Implement Automation Test using Serenity BDD Framework — Part I

Novita Tamba
3 min readJun 9, 2020

When you are asked to test web applications, the popular answer would be Selenium. But how if there is another one which supports more than just automate web application?

The Fundamental

Serenity (previously known as Thucydides) is an open-source framework which wrapper over Selenium and BDD tools. This tool helps you write better, more effective automated acceptance tests, and use these acceptance tests to produce living documentation.

In more, Why use Serenity Framework in automation test?

  • It is an open-source framework that supports multiple platform automation testing, like UX Testing, API Testing, Mobile Testing.
  • Serenity focus to built well-structured, and maintainable acceptance criteria.
  • Integrate with popular automation tools likes Selenium WebDriver, BDD Libraries like JBehave/Cucumber JVM, JUnit, Appium, even test management like JIRA.
  • Simplified code by providing much built-in functionality.
  • Report on Functional Testing Coverage by mapping requirements and test results.
  • Produce illustrated, narrative reports about running test and % of testing results.

Here are simple practical steps to test web application https://parabank.parasoft.com/parabank/index.html using BBD Style by Serenity Framework.

#1 Setup Environment

  1. Install Editor. In this case, I’m using Intellij IDEA 2019.
  2. Install JDK 13 (Don’t forget to add Installed JDK to your System path).
  3. Install Maven Builder
  4. Install Firefox / Chrome Driver

Tip: how to test geckodriver is properly installed is by open cmd and type geckodriver. It should be displayed geckodriver version

#2 Project Structure & Test Code

At first, we need to create Maven Project and Configure Maven Dependencies for Serenity or you can simply import maven starter project from the founder :)

https://github.com/serenity-bdd/serenity-junit-starter.

Don’t forget to add the Cucumber dependencies dan JAVA Faker for Test Data (optional)

Let’s look at the below example. Suppose we are building a bank application. In Agile terms, the corresponding user story might look like this:

We can store the features file under src/test/resources/features.

Implement Steps Class

Step libraries are often used to represent actors or persona who interact with the application. In the story definition above, a user was trying to register to Para Bank Application.

Basically @Steps annotation will indicate a step library in Serenity Test Code. By put this definition, Serenity will do his part to instantiate the object.

Cucumber runs the test via JUnit and needs a dedicated test runner class to run the feature files. Put@CucumberOptions class to provide the root directory where the feature files can be found.

Test Code except features should be under src/test/java.

#3 Test Report

After done with the code, we can run the test by command mvn clean verify serenity:aggregate

The report would be generated under project/target/site/serenity. You should find an index.html file.

Summary Diagram after finish Running Tests
Test Report Detail for Simple BDD Test

#4 To sum up

In my opinion, Serenity help us not only writing test code but also give us tracing requirements in living reports. The code is maintainable and easy to understand. It’s a good framework too since it not bounded only for web applications.

Source

https://johnfergusonsmart.com/serenity-bdd/

https://serenity-bdd.github.io/theserenitybook/latest/index.html

--

--