Custom Implementation

As all instances are managed by Spring tapir enables you to overwrite any implementation, even those provided by tapir’s core or any optional module. This offers maximum flexibility to the user.

Handle this feature with care! Violating contracts might lead to elusive errors.


tapir’s Selenium integration captures a screenshot every time a test step fails. The name of the screenshot has the following format: 


Imagine you want to change this identifier to


The name is built by ScreenshotListener whose bean name is its fully qualified name de.bmiag.tapir.seleniumexecution.listener.ScreenshotListenerr.

The FilesystemAttachmentListener captures the attachment, stores it on the disk and outputs the file path:

The attachment GoogleTest.assertTitle-FailScreenshot has been written to {somepath}/GoogleTest.assertTitle-FailScreenshot.png

We can register a custom screenshot listener which uses our identifier:


class CustomScreenshotListener extends AbstractExecutionListener {
    ScreenshotService screenshotService
     * @since 2.0.0
    override void stepFailed(TestStep testStep, Throwable throwable) {
        val name = '''«»-«»-Failure'''

This would just add another ExecutionListener. In the end you get two screenshots. 

The attachment GoogleTest.assertTitle-FailScreenshot has been written to {somepath}/GoogleTest.assertTitle-FailScreenshot.png
The attachment GoogleTest-assertTitle-Failure has been written to {somepath}/GoogleTest-assertTitle-Failure.png

That’s not the desired behaviour as we would like to override the old ScreenshotListener. Unfortunately Spring does not allow to override a bean via component scan. You have to declare the bean in your configuration class:


public class MyConfiguration {
    def CustomScreenshotListener customScreenshotListener() {
        return new CustomScreenshotListener

This declaration overrides the bean de.bmiag.tapir.seleniumexecution.listener.ScreenshotListener. The result is this logged message:

The attachment GoogleTest-assertTitle-Failure has been written to {somepath}/GoogleTest-assertTitle-Failure.png


Overriding a bean is quite simple. All you need to know is the name of the bean you would like to override. Of course you have to make sure that the type of your bean is compatible with the type of the overridden bean.

Beans which are registered via component scan cannot override other beans. You have to declare them in your module's configuration class.