Skip to content

September 23, 2011

19

Introducing Thucydides

by jfsmart

What is Thucydides

Thucydides is a tool that lets you use WebDriver-based unit or BDD tests to write more flexible and more reusable WebDriver-based tests, and also to generate documentation about your acceptance tests, including a narrative description of test, along with the corresponding screen shots, and also high-level summaries and aggregations of the test results.

How does it work

Let’s have a look at one of the most common ways of using Thucydides:

1) What are you working on?

First, you create a model of the features and user stories you intend to implement in the next iteration:

2) How do you know it’s done?

Next, describe your high-level acceptance criteria in business terms. Here, we are using easyb, but you could also use just plain JUnit (and soon, Cucumber, Fitnesse, and other popular BDD tools):

3) Details, details

Now, flesh out your acceptance criteria in terms of high level steps (but don’t worry about the implementation yet – we are still thinking “what”, not “how”). Once this is done, you will have a pending acceptance test.

Or, if you prefer JUnit, you could do this:

4) Implement the steps

Now implement the actual test steps using either WebDriver page objects or other test steps. Here you start thinking about implementation:

5) Implement the Page Objects

Next you will need to implement your page objects, if you are not reusing existing ones (which tends to often be the case). These are almost just run-of-the-mill WebDriver page objects, but with a few enhancements:

6) Check out the reports!

Now, when you run your tests, Thucydides will produce a narrative-style report describing not only whether the test succeeded, but what it did:

7) And the pretty pictures

You can also step through the test from the user’s perspective, seeing a sequence of screenshots:

7) Don’t forget the high-level view

Thucydides also provides nice high-level reporting. Here is a report showing all the acceptance criteria for a particular story:

You can also get a high-level picture of your application, in terms of features, stories and acceptance criteria:

About these ads
Read more from Tutorials
19 Comments Post a comment
  1. Frank
    Jun 12 2012

    What I don’t get is how to parameterize the tests with various webdrivers to run tests against different browsers.. Isn’t that what they should do? Is there a TestNG attachment planned?

    Reply
    • Jun 12 2012

      I would typically not use parameterized tests for this, as I would do the cross-browser testing for the whole test suite, not for an individual test. To do this, I would usually set up a parameterized Jenkins test and pass in different values for the webdriver.driver system property, either running the tests directly on the build server or using a service like SauceLabs.

      Yes, there is a TestNG plugin in the pipelines.

      Reply
  2. I’m trying the archetypes, and I have a couple of issues:

    (i) after instantiating a project with the thucydides-simple-archetype,
    mvn test thucydides:aggregate doesn’t run any tests – surefire says ‘tests are skipped’ and the integration-test phase does not trigger
    (mvn verify t:a does run the Junit tests)

    (ii) I can’t get any selenium driver to instantiate (whichever archetype I use). This one is probably a problem in my settings or something, but I can’t figure it out. The test fails with ‘could not instantiate class org.openqa.selenium.firefox.FirefoxDriver’ (or chrome etc)

    Reply
    • Sep 5 2012

      (i) The web tests in the archetype are configured to run in the integration test phase, so “mvn verify” should suffice to both run the tests and generate the reports.
      (ii) What version of Firefox are you using? Sometimes the latest version of Firefox breaks the Selenium driver until they update the APIs. Chrome needs special configuration (see http://code.google.com/p/selenium/wiki/ChromeDriver)

      Reply
  3. Ignacio
    Oct 24 2012

    Hi, I have been working on ATC with Chrome and JBehave, but I can not get selenium works correctly all time. Sometimes, I get errors like: element is not clickable or it was not found. I used a workaround, but not always work. It is unbelieve that, if I run 10 times the ATCs, at least 3 times failed. Or, if I run each ATC isolated, they run ok. But, if I run all togheter, sometimes they failed.

    Reply
  4. Nov 23 2012

    This sounds like a timing issue – if your application uses AJAX in one way or another, you often need to wait until elements are ready on the screen before using them.

    Reply
  5. Ravinder
    Jan 3 2013

    How to run a single junit test

    Reply
    • Jan 3 2013

      The same way you run a single JUnit test normally – either directly in your IDE, or from the command line, e.g.

      mvn test -Dtest=MyTest

      Reply
  6. Maxim
    Feb 19 2013

    Hello from Ukraine.

    Do you have any plans about TestNG support in near future?

    Reply
    • Feb 19 2013

      It’s on the list, but I don’t know when I’ll get round to it. I’m not too familiar with the TestNG internals myself, but I’d be happy to guide anyone who would like to have a go.

      Reply
      • Maxim
        Feb 20 2013

        Thanks

  7. Utsav
    Feb 21 2013

    How to run a single thucydides story ?

    Reply
    • Feb 21 2013

      Can you elaborate ? If you are using Maven, you could run a single testcase using -Dtest=.

      Reply
      • Utsav
        Feb 22 2013

        Thanks for your response Rahul, I am using Maven and have created a Thucydides project, I want to run a specific test story at a time from maven, like the way we can specify which junit tests we want to execute.

        Thanks!

  8. Gennadiy
    Feb 22 2013

    I need help. I have an issue when I use in PageObject url with slash at th end. For example: I try to use @DefaultUrl(“www.xxx.com/), but actually firefox try to open url without slash “www.xxx.com” and I get 404. Could somebody help me solve it?

    Reply
    • Gennadiy
      Feb 22 2013

      redetermination, url looks like “https://xxxx.xxx.com/qa/web-ui/”

      Reply
  9. Mar 3 2013

    What version of Thucydides are you using? This looks like an issue that was fixed in version 0.9.100

    Reply
  10. Mar 13 2013

    Hello John,

    I really like the structure Thucydides brings to the WebDriver tests – I’m very impressed. However, there are some issues that I cannot figure out.

    1) I see the “ByJquery” and “ByjQuerySelector”, however neither in the docs nor in the blog I couldn’t find any reference on how to use it. (Is there any way?) I really like how Arquillian guys have implemented their own FindBy (http://arquillian.org/blog/tags/graphene/) – would really like to see something similar in Thucydides.

    2) I like how jBehave has @BeforeScenarios idea – this is where it would have been good to just open one instance of the Browser and reuse it through the entire tests. Opening-Closing the Browser take a big chunk of the test-time. (especially when test count goes over 150-250)

    I’ve recently converted from Python – Selenium where I had everything I needed – to Java and currently in search of the best framework for WebDriver. Thucydides seems to be the one, if only (1)-st question can be solved. Xpath is not an option (due to the IE), and there is no other way (at least that I’m aware of) that I can get element by “text” property.

    Your help would be really appreciated, and when I get more comfortable with Java, who knows – maybe I can contribute.

    Thanks!

    Reply
    • Mar 13 2013

      Hi Alexo,

      There will be a Thucydides @FindBy annotation in the next release or two, that will include the jquery integration. I’ve been working on integrating directly with Graphene, but it isn’t as simple as it looks, so many of the Graphene features will also be available in Thucydides.

      Regarding keeping the browser open for many tests: at the moment you can keep the browser open for all of the scenarios in a JBehave story. I may look into allowing the browser to be kept open for longer, but this can be problematic, as Firefox (for example) tends to crash (memory leaks) if you run it for too long.

      I would suggest continuing this discussion on https://groups.google.com/forum/?fromgroups#!forum/thucydides-users, as that is where we are trying to centralize discussion on new Thucydides features.

      - John.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

Follow

Get every new post delivered to your Inbox.

Join 2,671 other followers

%d bloggers like this: