Ask a Question

Hook after and before group of tagged scenarios

matiq
New Contributor

Hook after and before group of tagged scenarios

Hi,

I'd like to suggest you adding new kind of hook destined for running before and after group of scenario that can be used also by scenario outlines.

 

I'm unable to run hooks before and after group of tagged scenarios. I want to avoid creating test data for each scenario in group, the reason is because data setting takes a lot of time. It would be good to use conditinal hooks, so that select specific scenarios.

 

New before hook should be run when the first scenario in group is starting, whereas new after hook ought to be started when last scenario will be finished. In case group with only one scenario, the hooks should be started before and after single scenario. I suggest to use following names for hooks: @BeforeGroup and @AfterGroup.

 

Example usage, where hooks are running before and after group of scenarios tagged as @Game:

# The first scenario in group
@game Scenario: Maker starts a game When the Maker starts a game Then the Maker waits for a Breaker to join
# The second scenario in group
@game Scenario: Breaker joins a game Given the Maker has started a game with the word "silky" When the Breaker joins the Maker's game Then the Breaker must guess a word with 5 characters
@BeforeGroup("@game")
public void doSomethingBeforeGroup(Scenario scenario){
}

@AfterGroup("@game") public void doSomethingAfterGroup(Scenario scenario){ }

Regards

3 REPLIES 3
aslakhellesoy
Moderator

Hi @matiq

 

We won't be adding this feature as it would lead to coupling between scenarios. Slow tests are usually an indication that your application is too tightly coupled.

------
I'm the creator and lead developer of Cucumber Open.

Hi,

Thanks for your reply.

The hooks would be responsible for set up environment for some groups of autotests and it won't be lead to coupling between scenarios. The autotests aren't slow, but environment configuration takes a lot of time for some of them.

 

From my perspective they can be work similar to hooks "beforeAll" and "afterAll", but new ones will be destined for set up environment for group of autotests.

 

Regards

mpkorstanje
Occasional Contributor

Cucumber currently doesn't support this. You may however be able to replicate this by using a conditional before hook and JUnits after all hook.

 

In the conditional before hook, if the environment hasn't been created, you create it. In the after all hook, you clean up all created environments.You can keep a reference to all created environments in a static variable.

cancel
Showing results for 
Search instead for 
Did you mean: