Cucumber-jvm Hooks when Scenario is passed or failed


In <strong>Jbehave</strong> we can execute method upon outcome of scenario success/failure. One of the below mentioned methods will execute after failure and success.

@AfterScenario(uponOutcome=AfterScenario.Outcome.SUCCESS) public void afterSuccessfulScenario() { // Some code to execute... } @AfterScenario(uponOutcome=AfterScenario.Outcome.FAILURE) public void afterFailedScenario() { // Some code to execute... }

I'm trying to achieve the same thing in <strong>Cucumber-jvm</strong>. The scenario Hooks @Before and @After will execute after each scenario. But I want to execute some code for each failure scenario.

I am not sure how to implement it in cucumber-jvm. Any clue?


You can achieve it using cucumber-jvm hooks. If a hook receive a <a href="http://cucumber.github.io/api/cucumber/jvm/javadoc/cucumber/api/Scenario.html" rel="nofollow">Scenario</a> as a parameter, you can know if it has failed or not.


@After public void afterScenario(Scenario scenario) { if (scenario.isFailed()) { // Some code to execute... } if(scenario.isPassed()) { // Some code to execute... } }

Note the import of @After:

import cucumber.api.java.After;

Hope it helps.


  • How to generate skeleton using cucumber feature file
  • Logging Messages from Java Class back to the Karate Report
  • Cucumber Stopping Execution after Time in Steps
  • sending cucumber reports via jenkins Editable mail option
  • Folder specific cucumber-reporting without parallel run?
  • Cucumber-jvm Hooks when Scenario is passed or failed
  • Step definitions library for Meteor-cucumber/chimp
  • Query Elasticsearch JSON
  • Rerunning the failed scenario using Maven/Cucumber/Serenity
  • Configuring cucumber-guice
  • How to suppress Cucumber/Junit assertion stack trace
  • Maven cucumber reporting with multi-module maven project
  • Check text in a DOM element using Protractor
  • How to run a single row of a Cucumber scenario outline example table in RubyMine?
  • Multiprocessing in Python: how to implement a loop over “apply_async” as “map_async” using a callbac
  • Comparing elements in two lists when keeping duplicates is desired in Python
  • Replace any string in columns with 1
  • f:param to composite components
  • Get current user from inside the model in Sails
  • Segmentation Fault on MySQL2 / Ruby 1.9.3 / Rails 3.2
  • EntLib Way to Bind “Null” Value to Parameter
  • Passing “get” parameters doesn't work, parameter not visible in the link
  • Django model inheritance, filtering models
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • Get data from AJAX - How to
  • Can I display google adwords (AdView) in javafx on android
  • Bug in WPF DataGrid
  • Is possible to count alias result on mysql
  • Validaiting emails with Net.Mail MailAddress
  • sending/ receiving email in Java
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Cannot Parse HTML Data Using Android / JSOUP
  • Benchmarking RAM performance - UWP and C#
  • JTable with a ScrollPane misbehaving
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?