Search code examples
cucumberkarate

How can I execute the same lines of code after all scenarios in specific feature files in Karate?


How can I execute the same few lines of code after every specific scenario? For example, we have 'Background' defined at the top of our feature files. Is there a 'Footer' or something similar? Since I only want to execute this code on specific features, not our entire repository, I would need to add it to the specific feature file, but I don't want to add it to every single scenario in the feature file, I just want to add it once.

We have background, which executes at the beginning of each scenario:

Background:

*to start do this

to start do this as well*

I want something like this, to execute at the end of each scenario:

Footer:

*to finish do this

to finish do this as well*


Solution

  • Yes, there is an afterScenario hook: https://github.com/intuit/karate#hooks

    Background:
    * configure afterScenario = function(){ karate.log('hello') }