Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After Scenario Outline hook in Cucumber

I'm using Java and Cucumber. I need to do some actions after every scenario outline. I know there are @Before and @After hooks, but they are applicable to every scenario in Scenario Outline. Is there any possibility to launch some actions exactly after all scenarios in outline and not after every scenario?

Example:

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

I want to make execution in following way:

@Before actions

a value

b value

@After actions

@Before actions

//another scenario outline output

@After actions

like image 533
Solarsoul Avatar asked Oct 21 '25 05:10

Solarsoul


1 Answers

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 have specified tag1 as a tag.

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

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

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

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

like image 200
GaurZilla Avatar answered Oct 23 '25 19:10

GaurZilla