I'm using scenario outline in my code and wanted to execute some code before the start of scenario outline and some code after the scenario outline execution has completed.
I know there are @Before and @After annotations in cucumber but these gets executed before and after every scenario. So if I have a scenario outline and 3 rows of example data then @Before and @After will be executed each of then i.e. total 3 times each.
But I want to execute it only once, @Before scenario outline and @After scenario outline thats it! Is there any way to achieve this in cucumber-jvm?
//@Before (some code that should be executed before scenario outline execution begins)
Scenario outline
....
Examples:
|Header1 | Header2 | ..etc
|Data1 | Data2 |
//@After (some code that should be executed after scenario outline execution ends)
As far as i know there is no direct way, but you can tag your scenario and use the before and after hooks for tags as a workaround.
Here is an example:
Then you can use this in your Java code:
Here are tags described: https://github.com/cucumber/cucumber/wiki/Tags