Java – After the scene outline Hook in cucumber

After the scene outline Hook in cucumber… here is a solution to the problem.

After the scene outline Hook in cucumber

I’m using Java and Cucumber. I need to do something after each scenario outline. I know there are @Before and @After Hooks, but they apply to every scenario in the scene outline. Is it possible to initiate something exactly after all scenes in the outline instead of after each one?

Example:

   Scenario Outline: Some scenario
   Given given actions
   When when actions
   Then display <value>
Examples:
|value|
|a    |
|b    |

I want to do it as follows:

@ Before operation

A value

B value

@ Action post

@ Before operation

Another scenario outline output

@ Action post

Solution

Yes, you can use tags.

   @tag1
   Scenario Outline: Some scenario
   Given given actions
   When when actions
   Then display <value>
Examples:
|value|
|a    |
|b    |

Here we specify tag1 as the tag.

Now in the step definition, you can use something like this:

@Before("@tag1")
public void testSetup(){
    ...
} 

@After("@tag1")
public void testEnd(){
    ...
} 

These @before and @after are now specific to tag1.
I hope this helps.

Related Problems and Solutions