Please, change device orientation to portrait

by Ostap Elyashevskyy

Test Automation Framework. Serenity BDD: Getting Started

Following its subdued Latin origin, Serenity BDD is a real snatch for Test Automation Framework. Get familiar with this library from A to Z, as well as learn how to create simple projects and run the tests.

Following its subdued Latin origin, Serenity BDD (previously known as Thucydides) is a library for test automation which wraps and extends WebDriver/JUnit functionality. Serenity BDD is well documented and supported, but in references the old name can be used. The reason for changing the name is quite trivial: instead of wondering how Thucydides works, people were puzzled about how on earth to pronounce the word.

In the first part of my Test Automation Framework blog I described most of Serenity’s features. In this article you’ll get familiar with this library from A to Z, as well as learn how to create simple projects and run the tests. Keeping things simple and covering only the necessary steps, let’s get started!

Prerequisites

Serenity BDD (from now on let’s only use this name) requires the following tools to be installed:

  • Maven 3.0.x or higher
  • Java 5 or higher

In this example Eclipse will be used as the Integrated Development Environment (IDE), but you can use any editor you like.

Maven Configuration

To launch your tests through a command line, edit the Maven settings file:

[MAVEN_INSTALL PATH]\apache-maven-3.x.x\conf\settings.xml. Inside settings block add pluginGroups:

<pluginGroups>

<pluginGroup>net.thucydides.maven.plugins</pluginGroup>

</pluginGroups>

There are two ways to create a simple Maven project for Selenium 2 and JUnit: from command line or through IDE. In this case, a common line is used and then imported as a Maven project.

  1. Create test folder (e.g.: D:\repo\test) and move to the folder through the command line
  2. Type the next command and press enter:
    mvn archetype:generate -Dfilter=thucydides
  3. In the console window you will be asked to choose the type of the project, select:
    3: remote -> net.thucydides:thucydides-simple-archetype (Thucydides automated acceptance testing project using Selenium 2 and JUnit)
  4. You will be prompted for a version: select the latest version of Serenity BDD and press Enter
  5. When asked about:
    • groupID (value which identifies your project) type some identifier, e.g.: com.thu.tests
    • artifcatID (actually this value will be used as the name of your jar file): mytests
    When you see the version prompt, press enter to accept the default value or set any custom values
    When you see the package prompt, press enter to accept the default value
    When you see the Y:: prompt, press enter to accept default value
  6. Having pressed Enter, you should see the message: BUILD SUCCESS.

Generated Sample Overview

So, we have successfully generated a default test project. In case something goes wrong, you can download generated samples from repository. What do these sample tests actually do?

  • Open Wiktionary
  • Search for apple and verify search results
  • Search for pear and verify search results

Importing Project into Eclipse IDE

  1. Open Eclipse IDE
  2. Click File->Import->Maven-> Existing Maven project


  3. Choose the project directory where your Maven project was generated


  4. Click Finish

Launching the Tests

Before we can run the tests, we need to add WebDriver dependency into Maven pom.xml file:

Edit pom.xml which is located in the root of your project and insert inside block:

<dependency>

<groupid>org.seleniumhq.selenium</groupid>

<artifactid>selenium-java</artifactid>

<version>2.43.0</version>

</dependency>

Finally, we are ready to launch our tests: open the command prompt, go to your project and run the following command: mvn clean verify thucydides:aggregate

Tests will be launched in a Firefox browser by default. To run them in Internet Explorer use the following parameter:

-Dwebdriver.driver=iexplorer

NB: Serenity BD supports the following browsers: Firefox, Internet Explorer, Chrome, HTMLUnit.

Test Report

Go to the folder [Project directory]\target\site\thucydides and open index.html file in any browser.

As you may see below, the reports look really fancy, yet are very informative:

Project Structure

Now let’s take a look at the project structure:

Page objects. All your page object classes are stored here.

Tests. Tests consisting of detailed steps are stored here.

Test steps. Contains shared steps invoked from the tests.

Conclusions

Easy or not, we have managed to set up and launch our test, generate the report and get acquainted with the project structure. It was just an introductory tutorial on how to get Serenity BDD started to implement our tests with JUnit and WebDriver support. The next steps are to implement the same scenarios as BDD acceptance tests. More information and feature descriptions may be found on the home page of the project.