Reputation: 419
I try to execute a script to clean up db after features executions in cucumber. I use the before and after hook in the following fashion:
private static boolean skipActions = false;
@Before("@initData")
public void setupData() throws Exception {
if (!skipActions) {
initData();
skipActions = true;
}
}
for the before I can avoid the script to be called before each scenario using a static variable. But didn't figure out how to do it for the after hook:
@After("@clearData")
public void tearDown() throws Exception {
clearData();
}
is there a way to capture if the last scenario has executed and trigger clearData() only if that condition is fulfilled ? Is there a more elegant way of doing it ?
Upvotes: 0
Views: 579
Reputation: 458
So in ruby there is an at_exit hook. but this isn't cucumber, it's programmatically related. I would look inside your language to see if this is possible.
Failing that, you can store a class variable during your run of the number of failures. then if all of those have passed then you can do something.
Another way you could tackle it would be to wrap your execution job in something like jenkins, jenkins has nice simple out of the box methods for cleaning things up.
In Jenkinsfile's both declarative and scripted pipelines allow the calling of cleanWs()
as a groovy statement which then wipes the entire jenkins node.
Upvotes: 1