Test Class

In order to use test classes in your project, you need the tapir-execution module.

<dependency>
    <groupId>de.bmiag.tapir</groupId>
    <artifactId>tapir-execution</artifactId>
</dependency>

Structure

A test class (annotated with @TestClass) is an executable unit which contains at least one step. All the steps (annotated with @Step) declared in a test class are executed sequentially. The most simple test class looks like this:

@TestClass
class MyTest {
    @Step
    def void step1() {
        println("Step 1 is executed")
    }
}

Using Page Objects

Test classes should use page objects to interact with the SUT. Like any other Spring bean these page objects can be autowired by using Spring’s @Autowire annotation. You can find additional information about page objects in the dedicated chapter.

Hint
You can inject any bean by using @Autowired. This capability is not limited to page objects.
@TestClass
class MyTest {
 
    @Autowired
    MyPage myPage

    @Step
    def void step1() {
        myPage.textField.text = "Test"
    }
}

Extensions

In every Test class TapirAssertions is registered and all its visible members can be used in the test class:

@TestClass
class MyTest {
 
    @Autowired
    MyPage myPage

    @Step
    def void step1() {
        assertThat(myPage.textField.text, is("Test"))
    }
}

You can add custom extensions by using @UseExtension.

UseBean

You can use the annotation @UseBean to inject arbitrary beans into your test class. It adds the given bean classes under a default name as a field and adds Spring’s Autowired annotation. This works similar to @UseExtension, but does not add the new field as extension. This annotation is useful if you want to use multiple page objects in your test and don’t want to add each of them as a field.

@TestClass
@UseBean(MyPage)
class MyTest {
 
    @Step
    def void step1() {
        assertThat(myPage.textField.text, is("Test"))
    }
}

Documentation

Test classes can and should be documented. There is a dedicated chapter about Documentation.