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