7.1. Creating Step Libraries

Test steps are regular java methods, annotated with the @Step annotation. You organize steps and step groups in step libraries. A step library is just a normal Java class. If you are running web tests, your step library should either have a Pages member variable, or (more simply) extend the ScenarioSteps class, e.g.

public class JobSeekerSteps extends ScenarioSteps {
    public JobSeekerSteps(Pages pages) {
        super(pages);
    }


    @Step
    public void opens_jobs_page() {
        FindAJobPage page = getPages().get(FindAJobPage.class);
        page.open();
    }

    @Step
    public void searches_for_jobs_using(String keywords) {
        FindAJobPage page = getPages().get(FindAJobPage.class);
        page.look_for_jobs_with_keywords(keywords);

    }
}

Note that step methods can take parameters. The parameters that are passed into a step method will be recorded and reported in the Thucydides reports, making this an excellent technique to make your tests more maintainable and more modular.

Steps can also call other steps, which is very useful for more complicated test scenarios. The result is the sort of nested structure you can see in Figure 2.1, “A test report generated by Thucydides”.