how to execute an @AfterAll t execute something after all scenarios

1,785 views
Skip to first unread message

Styris

unread,
Dec 7, 2016, 11:28:26 PM12/7/16
to Cukes
Hi,

I have looked this up but not sure if there is a solution for this. I want to run a piece of code/script that is executed once after all the scenarios have been executed. One option is that my last Scenario can have a StepDefinition that runs that piece of code. But I am not sure if that is efficient. As far as I know Cucumber does not contain an @AfterAll hook like TestNG etc.
So, please tell, what is my option?

Thanks!

Paolo Ambrosio

unread,
Dec 8, 2016, 2:50:54 AM12/8/16
to cu...@googlegroups.com
Relying on a specific order of execution for scenarios and features is
really a bad idea.

If you are not using Spring DI (where you can specify a
"destroy-method" that is called when the bean is destroyed), try
reading this old topic:

https://groups.google.com/forum/#!topic/cukes/oQdJu4p6k1s

Cheers,
Paolo

Andrew Premdas

unread,
Dec 8, 2016, 3:19:28 AM12/8/16
to cu...@googlegroups.com
First of all when posting please follow the convention of putting your platform details in the subject. This helps you to get the appropriate answers.

There is an at_exit hook documented here https://github.com/cucumber/cucumber/wiki/Hooks#global-hooks.

All best

Andrew

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Styris

unread,
Dec 8, 2016, 5:55:53 PM12/8/16
to Cukes
Sorry for not following the convention. Thanks for your response but is there something  written in java that I can look at?


On Thursday, December 8, 2016 at 12:19:28 AM UTC-8, apremdas wrote:
First of all when posting please follow the convention of putting your platform details in the subject. This helps you to get the appropriate answers.

There is an at_exit hook documented here https://github.com/cucumber/cucumber/wiki/Hooks#global-hooks.

All best

Andrew
On 8 December 2016 at 04:28, Styris <kashi...@gmail.com> wrote:
Hi,

I have looked this up but not sure if there is a solution for this. I want to run a piece of code/script that is executed once after all the scenarios have been executed. One option is that my last Scenario can have a StepDefinition that runs that piece of code. But I am not sure if that is efficient. As far as I know Cucumber does not contain an @AfterAll hook like TestNG etc.
So, please tell, what is my option?

Thanks!

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Styris

unread,
Dec 8, 2016, 5:56:39 PM12/8/16
to Cukes
Are those Cucumber hooks? 
As in...do you have a java-specific example for an After or exit hook with Cucumber framework?

Paolo Ambrosio

unread,
Dec 9, 2016, 1:45:15 AM12/9/16
to cu...@googlegroups.com
Cucumber-JVM does not provide such hooks, but there are other ways to
do what you want by using Java or DI frameworks. The pure Java one is
in one of the examples and you can find the link to that in the thread
I mentioned in my previous email (Björn's answer).

Paolo
Reply all
Reply to author
Forward
0 new messages