Logo

Automated
Acceptance Testing with
Style

  • Home
  • OVERVIEW
    • Credits
  • DOWNLOADS
  • DOCUMENTATION
  • Learn
  • Wakaleo
    • About Us
    • Contact Us
  • HELP
Tool Integration
  • JUnit
  • JBehave
  • EasyB
  • JIRA
Tags
atdd bdd jbehave selenium web testing
Sample Reports
Home Blog Managing state between steps
Details
Jul21
Written by Super User

Sometimes it's useful to be able to pass information between steps. For example, you might need to check that a client's details entered into a registration form appear correctly on a confirmation page later on.

You could do this by passing values from one step to another, however this tends to clutter up the steps. Another approach is to use the Thucydides test session, which is essentially a hash map where you can store variables for the duration of a single test. You can obtain this session map using the Thucydides.getCurrentSession() static method.

As illustrated here, you can p

@Step
public void notes_publication_name_and_date() {
    PublicationDatesPage page = pages().get(PublicationDatesPage.class);
    String publicationName = page.getPublicationName();
    DateTime publicationDate = page.getPublicationDate();

    Thucydides.getCurrentSession().put("publicationName", publicationName);
    Thucydides.getCurrentSession().put("publicationDate", publicationDate);
}

Then, in a step invoked later on in the test, you can check the values stored in the session:

public void checks_publication_details_on_confirmation_page() {

    ConfirmationPage page = pages().get(ConfirmationPage.class);

    String selectedPublicationName = (String) 
Thucydides.getCurrentSession().get("publicationName");
    DateTime selectedPublicationDate = (DateTime) 
Thucydides.getCurrentSession().get("publicationDate");

    assertThat(page.getPublicationDate(), is(selectedPublicationName));
    assertThat(page.getPublicationName(), is(selectedPublicationDate));

}

If no variable is found with the requested name, the test will fail. The test session is cleared at the start of each test.

Events
More News
  • JavaOne 2012: Behavior-Driven Development on the JVM: A State of the Union

    Super User -Fri, Aug, 2012

Documentation
  • Official Thucydides Blog
  • Thucydides on Github
  • Thucydides User Manual
  • The Thucydides Company
Thucydides Release 0.8.31 - enhancements and bug fixes
Aug 03
Thucydides Release 0.8.31 is primarily a bug fix and enhancement release but goes a long way in making Thucydides more robust. We have added a couple of minor features and fixed issues related with... Read More...

Help and Support

...

Copyright © 2007 - 2012 Wakaleo Consulting

Thucydides development is lead and supported by Wakaleo Consulting,
a Sydney-based company that helps organisations optimize their software
development process. We provide consulting, training and mentoring
services in Agile Development Practices such as Continuous Integration,
Test-Driven Development, Acceptance-Test Driven Development,
Build Automation, Code Quality Practices and Automated Web Testing.

  • Home
  • OVERVIEW
  • DOWNLOADS
  • DOCUMENTATION
  • Learn
  • Wakaleo
  • HELP