• Home  / 
  • BDD
  •  /  jBehave + Selenium – Getting started with Thucydides – Part 1

jBehave + Selenium – Getting started with Thucydides – Part 1

What is Thucydides?

If you are getting started with Behavior Driven Development using Java and jBehave, I highly recommend you take a look at Thucydides. In a nutshell, Thucydides is an open source BDD library that allows you to create highly flexible reports/acceptance test documentation using Selenium 2 WebDriver.

Let’s take a look at how to install Thucydides in Eclipse and go over some of its main features.


Before we begin, I’ll assume that you have Maven installed and configured and the Eclipse maven plugin installed. (To learn more on how to install Maven, check out the Maven in 5 minutes guide. For Eclipse, make sure you have the Maven Integration (m2e) plugin installed.)

Two ways to install

There are two ways you can install Thucydides; one is directly from Eclipse and the other is by using the command line. I’ve had better success installing from the command line — some of the machines inside my company’s network don’t seem to like installing Thucydides in Eclipse. In any case, I’ll show you both ways.

How to install Thucydides from the command line

  • In Windows, click on start>run and enter cmd.
  • Navigate to the directory where you want your project to live.( I chose D:\MyFirstThucydides)
  • Enter the following at your command line prompt and hit enter:

mvn archetype:generate -Dfilter=net.thucydides:thucydides-jbehave-archetype

This is a Maven command that tells Maven we’re creating a new project, and that we want to create the project based on one of the Thucydides templates. Now let’s take a look at the other prompts

  • Because there are tons of Maven archetypes, we used a filter to return only the one that we are interested in: thucydides-jbehave-archetype. At the Choose a number or apply filter prompt, enter 1.

•    Next, select a version. Choose the latest version (as of now, that is 0.9.205).

  • Now enter a groupId for your project. This is any value you want to help identify your project uniquely across all projects (I’m going to name mine com.joecolantonio.mythucydides). Next, hit the enter key.
  • At the artifactId prompt, enter mythucydides (this will name our jar file), then hit enter.
  • At the version prompt, take the default value and hit enter.
  • At the package prompt, take the default and hit enter.
  • At the Y:: prompt, take the default and hit enter.
  • You should now see a BUILD SUCCESS message.

If you type dir at the command line you should see that it now contains a directory that is the same name that you used for its artifactId.

Open the Command Line Thucydides Project in Eclipse

•    Go to using File>Import

•    From the Import dialog, choose Existing Maven Projects.

•    Choose the Root Directory for the project you just created that contains the pom file:

•    Click Finish.

•    Under your Eclipse package explorer, you should see the demo Thucydides project structure that was automatically generated for you.

Now we’ll take a look at how to do the same thing directly from within the Eclipse IDE.

How to install Thucydides from the Eclipse IDE

  • Start Eclipse\File>New>Other>Maven>Maven Project

  • In the New Maven Project, select Use default Workspace location and click Next>.

    • In the Select an Archtype screen set:
      • Catalog: All Catalogs
      • Filter: Thucydides-jbehave-archtype:

    • Specify the following archetype parameters:

    • Group Id: com.joecolantonio.mythucydides
    • Artifact Id: mythucydides
    • Version: default value
    • Package: default value

If successful, no errors should appear and you should see the directory structure that Thucydides created automatically for you. We’ll take a look at each section individually, but first we need to add the Thucydides plugins to our maven’s setting.xml.

Add the Thucydides plugins to the setting.xml

The following setting allows Maven to invoke the Thucydides plugin from the command line.

  • Navigate to your Maven’s setting.xml, which can be found under the apache-maven-#/conf directory on your machine:

  • Right click on the settings.xml and choose edit. It should open in notepad.
  • Enter the following section:

    • Save the settings.xml file

    Run the Demo Test and View the Report

    Once the setting is configured for the Thucydides plugin, you can run your sample Thucydides tests. To do so, open up the command prompt, navigate to your project location and run the following command:

    mvn clean verify thucydides:aggregate -Dmaven.test.failure.ignore=true

    • In Eclipse, navigate to the target\site\thucydides directory:

    • Find the index.html file.
    • Right click on it and open it with the web browser.

    You should now see the report for the sample project you just ran. Note how much better the Thucydides report is compared to the standard jBehave report!

    In future blog posts, we’ll take a detailed look at the Thucydides directory structure and report feature.

Click here to add a comment