Serenity BDD: What is it? Where is it used?
Serenity BDD is an open source library that helps developers and testers write maintainable automated acceptance and regression tests faster. It also uses the test results to produce illustrated, narrative reports that document and describe what your application does and how it works. A developer can build Serenity test suites using Maven, Gradle, or Ant. Serenity BDD provides strong support for automated web tests using Selenium 2. To learn more about the basic concepts of Behaviour Driven Development or BDD please refer to the link below.
In this blog series we explain how to
Part 1: Install Serenity BDD and configure the environment
Part 2: Build sample Serenity project/test suite using maven
Part 3: Configure an existing ADF Application using maven
Part 4: Create Serenity test suite for the maven-based Oracle ADF application
Part 5: Continuous Integration of Serenity test suite using Jenkins
PART 2: Build sample Serenity project/test suite using maven
Create a new maven project (or import the existing if you already have one). I have attached the sample maven project, download and import it to run and check if the installations, setup was done correctly.
Download the zip file (Install_Check_Sample.zip) and unzip to a location where you have your Eclipse projects are saved.
Open Eclipse IDE select import from the File drop down as shown below File>Import
Select Existing Maven Projects in the popup and click Next
Enter the location of the Maven project, select the pom.xml checkbox and click on Finish.
Once the Sample Maven project is imported the project structure looks like below
Add dependencies in pom.xml file (if project is imported pom.xml already exists, ignore this step). The attached sample test suite has the below pom.xml, added detailed explanation of plugins.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<name>Automation Region suite</name>
<!-- If you are using internet explorer driver or gecko driver please use the below code -->
<!-- <webdriver.driver>iexplorer</webdriver.driver> -->
<!-- <webdriver.driver>firefox</webdriver.driver> -->
<!--This dependency corresponds to the testing library we are using, JUnit in our case.
Other testing libraries can be JBehave and Cucumber-->
<!-- The below dependencies are for api module and simple bindings for the logging frameworks -- >
<!--Assertion Libraries for Rich and fluent assertions for testing in Java →
<!-- The maven-compiler-plugin is used to compile the sources of your project. the default source and target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as shown below, to use the Java 8 language features use 1.8 -- >
<!-- We need the below maven-failsafe-plugin plugin to run Serenity tests as integration tests, using this plugin the build will not immediately fail when a test fails and will continue until it generates the Serenity aggregate reports before failing at the end. -- >
<!-- The maven-surefire-plugin is designed for running unit tests and if any of the tests fail then it will fail the build immediately. Make sure you have the <skip>true</skip> set when running the integration tests (the tests will run twice if this is not set) -- >
<!-- The Serenity core libraries version 1.5.3 artifactId is ‘serenity-core’ unlike the previous version which has artifactId as ‘core’ . This version of serenity is compatible with Selenium 3.4.0 -- >
<!-- Binding the aggregate goal plugin to the post-integration-test phase is to run the tests and to generate the reports when we run the following the command mvn verify -- >
Thucydides.properties / Serenity.properties File.
This file is used to setup the system properties, web drivers and their capabilities. I have the below setup for my sample project. The commented lines are for using IE explorer or firefox drivers.
webdriver.chrome.driver = C:\\chromedriver.exe
Create java classes to start writing test cases( downloaded sample project will have the below) . I will explain how to structure and start coding the serenity tests using selenium commands in my next blog.
Run the java class/test case(with name ending in Test.java as specified in the pom.xml) as junit if you want to run the tests individually while unit testing as shown below.
Run the integration tests (all the tests in the test suite) using mvn verify command on cmd in the project folder to run the integration tests.
( ex: C:\SerenitySample mvn verify)
In this sample we are using Chrome driver. We cannot specify ‘webdriver.chrome.driver = C:\\chromedriver.exe’ in the properties file for iexplorer and firefox instead the driver location should be specified in the command line as shown below when executing tests.
mvn verify -Dwebdriver.ie.driver=C:\IEDriverServer.exe
mvn verify -Dwebdriver.gecko.driver=C:\geckodriver.exe
Below is the sample log which appears when the test suite is run successfully.
The test results are generated as a HTML report (Index.html) in the below location and are very descriptive in nature with screenshots. This is one of the main feature of Serenity BDD which make the testing process a living documentation.
C:\(Eclipse Workspace path)\FusionAppliedAutomation\target\site\serenity\Index.html
Below are the screenshots of the report generated for our sample project
Click on the Test name under tests to see the details steps being tested with screenshots, outcomes and duration took for the test to execute.
If you were able to see the generated reports saying tests result outcomes as SUCCESS, Congrats!! you have successfully setup Serenity and ran your first automated test.
Download Sample Project
Latest posts by hareesha muppalaneni (see all)
- Test Automation and CI using Serenity BDD & Jenkins for an Oracle ADF Application: Part 4 of 5 - January 4, 2018
- Test Automation and CI using Serenity BDD & Jenkins for an Oracle ADF Application: Part 3 of 5 - December 26, 2017
- Test Automation and CI using Serenity BDD & Jenkins for an Oracle ADF Application: Part 2 of 5 - December 21, 2017