Skip to content

Archive for

30
Sep

Thucydides Release 0.4.10 – Spring Integration


A new version of Thucydides – version 0.4.10 – is now available in the Maven repositories. In this version, we have added the Spring Integration features discussed in detail here, as well as a few small improvements and a minor bug fix.

Advertisements
29
Sep

Using Spring dependencies in your acceptance tests with Thucydides


If you are running your acceptance tests against an embedded web server (for example, using Jetty), it can occasionally be useful to access the service layers directly for fixture or infrastructure-related code. For example, you may have a scenario where a user action must, as a side effect, record an audit log in a table in the database. To keep your test focused and simple, you may want to call the service layer directly to check the audit logs, rather than logging on as an administrator and navigating to the audit logs screen.

Spring provides excellent support for integration tests, via the SpringJUnit4ClassRunner test runner. Unfortunately, if you are using Thucydides, this is not an option, as a test cannot have two runners at the same time. Fortunately, however, there is a solution! To inject dependencies using a Spring configuration file, you just need to include the Thucydides SpringIntegration rule in your test class. You instantiate this variable as shown here:

@Rule
public SpringIntegration springIntegration = new SpringIntegration();

Then you use the @ContextConfiguration annotation to define the configuration file or files to use. The you can inject dependencies as you would with an ordinary Spring integration test, using the usual Spring annotations such as @Autowired or @Resource. For example, suppose we are using the following Spring configuration file, called ‘config.xml’:

<beans>
    <bean id="widgetService" class="net.thucydides.junit.spring.WidgetService">
        <property name="name"><value>Widgets</value></property>
        <property name="quota"><value>1</value></property>
    </bean>
    <bean id="gizmoService" class="net.thucydides.junit.spring.GizmoService">
        <property name="name"><value>Gizmos</value></property>
        <property name="widgetService"><ref bean="widgetService" /></property>
    </bean>
</beans>

We can use this configuration file to inject dependencies as shown here:

@RunWith(ThucydidesRunner.class)
@ContextConfiguration(locations = "/config.xml")
public class WhenInjectingSpringDependencies {

    @Managed
    WebDriver driver;

    @ManagedPages(defaultUrl = "http://www.google.com")
    public Pages pages;

    @Rule
    public SpringIntegration springIntegration = new SpringIntegration();

    @Autowired
    public GizmoService gizmoService;

    @Test
    public void shouldInstanciateGizmoService() {
        assertThat(gizmoService, is(not(nullValue())));
    }

    @Test
    public void shouldInstanciateNestedServices() {
        assertThat(gizmoService.getWidgetService(), is(not(nullValue())));
    }
}

Other context-related annotations such as @DirtiesContext will also work as they would in a traditional Spring Integration test. Spring will create a new ApplicationContext for each test, but it will use a single ApplicationContext for all of the methods in your test. If one of your tests modifies an object in the ApplicationContext, you may want to tell Spring so that it can reset the context for the next test. You do this using the @DirtiesContext annotation. In the following test case, for example, the tests will fail without the @DirtiesContext annotation:

@RunWith(ThucydidesRunner.class)
@ContextConfiguration(locations = "/spring/config.xml")
public class WhenWorkingWithDirtyContexts {

    @Managed
    WebDriver driver;

    @ManagedPages(defaultUrl = "http://www.google.com")
    public Pages pages;

    @Rule
    public SpringIntegration springIntegration = new SpringIntegration();

    @Autowired
    public GizmoService gizmoService;

    @Test
    @DirtiesContext
    public void shouldNotBeAffectedByTheOtherTest() {
        assertThat(gizmoService.getName(), is("Gizmos"));
        gizmoService.setName("New Gizmos");
    }

    @Test
    @DirtiesContext
    public void shouldNotBeAffectedByTheOtherTestEither() {
        assertThat(gizmoService.getName(), is("Gizmos"));
        gizmoService.setName("New Gizmos");
    }

}
28
Sep

Thucydides Release 0.4.9 – improved issue tracking and JIRA integration


A new version of Thucydides – version 0.4.9 – is now available in the Maven repositories. This release provides support for the new Selenium 2.6 ExpectedConditions (see here for details), and also focuses on new features for integration with your issue tracking system. Read more »

26
Sep

Using Selenium 2.6 ExpectedConditions with Thucydides


Selenium 2.6 provides a new API that allows more fluent wait conditions, such as waiting for several fields to be visible or enabled. This has been integrated into the Thucydides PageObject class with a helper method to make it a bit easier to use. Read more »

26
Sep

Thucydides 0.4.8 Released


A new version of Thucydides – version 0.4.8 – is now available in the Maven repositories.

One of the most important improvements in this latest version is that it uses Selenium 2.6, which supports all versions of Firefox from 3.0 to 7. Previous versions of Selenium did not work well with Firefox 6 and 7.

Other improvements have been made in the reporting features. By default, Thucydides opens a browser with a width of around 1000px. Sometimes, this is not enough, and you need a larger window to see all of the elements on your page in the screenshots. Thucydides 0.4.8 lets you define the witdh of the browser Thucydides opens via the thucydides.browser.width command line option. Read more »

25
Sep

Completing the circle – Automated web tests as a team communication tool


A short presentation that introduces the philosophy behind the Thucydides Acceptance Testing library:

Acceptance Test Driven Development, or ATDD, has proven to be a very effective technique, both for driving and guiding development, and for enhancing communication between developers and other project stakeholders. But why stop there? Well designed Acceptance Tests can also act as a formidable documentation source and communication tool. Indeed, when written in a narrative, BDD-type style, Acceptance Tests have the potential to document in detail how the user interacts with the application.

23
Sep

Introducing Thucydides


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. Read more »