0

I am using Serenity with BDD and need to perform a teardown step that must get executed after completion of each Scenario. Also, this teardown step should not be visible to report as it is technical thing and nothing to do with behavior to be exposed as part of cucumber such as releasing few expensive resource that got

I used cucumber's @After annotation which is working as expected, but the problem is now this step is also shown in my Report which I don't want to be visible.

Could someone please suggest me a solution that allows me to perform teardown step that gets executed per scenario but should not be added as step in my Serenity Report.

Current Solution I have is which does not satisfy my need:

Step Definition Class has following method:

@After
 public void tearDown() {
     systemAction.deleteCostlyResource(id);
 }

but @After annotation makes it a candidate for Reporting Step.

Filipe Freire
  • 823
  • 7
  • 21
Ram
  • 117
  • 1
  • 2
  • 8

1 Answers1

0

If you are using Dependency Injection, you could have your DI framework teardown the resources at the end of the scenarios?

For instance, if you are using Spring: If the "costly resource" is a class that you yourself have created, mark it with:

@Component
@Scope("cucumber-glue")

If the "costly resource" is not a class you created, but provided by a framework or whatever, you can register it as a bean in your spring (test)configuration and mark it with a "destroy method". For example, to register Selenium WebDriver using annotation based configuration and making sure to quit after each Scenario, mark it with:

@Bean(destroyMethod = "quit")

In this example, quit() is WebDriver's method to quit(). In your situation, call "costly resource's" quit method, or equivalent thereof.

Marit
  • 2,399
  • 18
  • 27