jBehave + Selenium – Getting started with Thucydides – Part 1

By Joe Colantonio / December 19, 2013

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.

Pre-Requirements

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:
    net.thucydides.maven.plugins


    • 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.

Leave a comment:

16 comments
calioCat - December 21, 2013

Hi,
Thank you very much for useful article :)
I’m new to Thucydidies and I wonder how can we integrate Thucy + Maven + JBehave + TestNG.

Thanks and Best Regards.

Reply
    Joe Colantonio - December 21, 2013

    Awesome – thanks! More Thucydides post are coming soon. Let me know if there is anything you would want to know more about. Cheers~Joe

    Reply
Hiru - December 26, 2013

Hi ,
Thank you very much for your valuable post friend.meanwhile i didn’t get the pie chart report you have any idea for the root cause ?
/Hiru

Reply
    Joe Colantonio - December 27, 2013

    Thanks – working on more post and a video for this. After you run the test do you have a index.html under Under target\site\thucydides? For some reason when I run straight from the IDE the report is not generated. I have to run from the command line using the following:

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

    Reply
Henry Floyd - February 27, 2014

Hey Joe

Thanks for the great site. I’m a big fan and I have to admit you though processes are very similar to mine (great minds think alike).

Anyway I was also a big fan of QTP and QC (integration). I loved having the benefit of have all my test run history for qtp in QC. So along those lines have you yet found any test management application that is similar to QC for Selenium or Thucydides (horrible name for a framework but an awesome pierce of work by John Smart). I have been using the framework since last October and would to hear more about your experiences. Keep up the great work.

Reply
    Joe Colantonio - February 28, 2014

    Thanks Henry – I just started using Thucydides a few months ago and I really like it. We basically have all our tests stored in Perforce and run everynight in a CI tool (Electric cloud). Each nightly runs attaches the Thucydides report to it so we can see what historical data for every run and see what the actually tests results where. It is not perfect – I agree its not as good as qc/alm integration — yet. I’m going to try to post more on Thucydides this year for what I find as our project grows.

    Reply
sriikandan - April 12, 2014

Hi Joe,

My script is not completing after test execution and I have to terminate it explicitly.
I could not see the index.html report from thucydides but I could see a testcase level report at target folder.
Could you please help in fixing this issue.

Reply
    Joe Colantonio - June 22, 2014

    Are you using the built in thucydides page object methods to handle the driver management for you? i have seen this issue when people code their own driver methods

    Reply
Shan - June 4, 2014

Thanks for the valuable post , I tried it but I’m getting the following exception. Can you please guide if I’m missing anything here.
[INFO] Preparing archetype:generate
[INFO] No goals needed for project – skipping
[INFO] [archetype:generate]
[INFO] Generating project in Interactive mode
[WARNING] Error reading archetype catalog http://repo1.maven.org/maven2
org.apache.maven.wagon.TransferFailedException: Error transferring file
at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputD
ata(LightweightHttpWagon.java:104)
at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:68)
at org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.do
wnloadCatalog(RemoteCatalogArchetypeDataSource.java:119)
at org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.ge
tArchetypeCatalog(RemoteCatalogArchetypeDataSource.java:87)
at org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(D
efaultArchetypeManager.java:216)
at org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(D
efaultArchetypeManager.java:205)
at org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.get
ArchetypesByCatalog(DefaultArchetypeSelector.java:200)
at org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.sel
ectArchetype(DefaultArchetypeSelector.java:71)
at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execu
te(CreateProjectFromArchetypeMojo.java:197)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:454)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:559)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:513)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:483)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:331)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:228)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:345)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:132)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:290)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown
Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Sour
ce)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputD
ata(LightweightHttpWagon.java:83)
… 26 more
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[INFO] Your filter doesn’t match any archetype, so try again with another value.

[INFO] ————————————————————————
[INFO] BUILD SUCCESSFUL
[INFO] ————————————————————————
[INFO] Total time: 44 seconds
[INFO] Finished at: Wed Jun 04 08:07:46 CDT 2014
[INFO] Final Memory: 17M/32M
[INFO] ————————————————————————

Reply
Shan - June 10, 2014

Thanks Joe!! it worked.

Reply
Gurpreet - February 7, 2015

I am getting below error can you help me out its opening browser but not entering default url
net.thucydides.core.webdriver.UnsupportedDriverException: Could not instantiate
class org.openqa.selenium.firefox.FirefoxDriver

Reply
    Joe Colantonio - February 11, 2015

    Are you still having this issue? What version of Firefox is installed on your machine? How are you running as a junit test or as a maven test?

    Reply
Naveen - April 13, 2015

Hi,
I have created one project using JBehave, Project have one or more story files. Each story contains one or more scenarios. Here i am facing the issue is, when executing the stories, each scenario is executing on its own priver browser(WebDriver). I want to execute all story–>scenarios in single browser(WebDriver).
How can i fix this. Plz help me on this.

Reply
    Joe Colantonio - May 24, 2015

    You might be able to use the thucydides.use.unique.browser property which allows you to set this to run all web tests in a single browser. Just add this to your thucydides.properties file. If you do not have a thucydides..properties file create and add this value to see if it helps. Check out chapter 14 for all the property files setting you can set: http://thucydides.info/docs/thucydides-one-page/thucydides.html

    Reply
Click here to add a comment

Leave a comment: