-1

I searched for exact reason & significance of using Scenario scenario parameter ( import cucumber.api.Scenario; ) but didn't clear answer.

https://github.com/cucumber/cucumber/wiki/Hooks > Scenario Hooks section doesn't explain in detail.

Please give real world examples of the benefits

vikramvi
  • 3,312
  • 10
  • 45
  • 68

1 Answers1

1

You get access to these methods:

enter image description here

Benefits depend on you project needs. Try them out and see where in your project they can help.

Here are some exmples:

Get scenario name in the @Before hook, print it or save it for other uses (like reports):

@Before
public void before(Scenario scenario) {
    String scenarioName = scenario.getName();
    System.out.println("Scenario: " + scenarioName);
}

Get the scenario status in the @After hook.

@After
public void after(Scenario scenario) {
    if (scenario.isFailed()) {
        // Do stuff
    }
}
Daniel Fintinariu
  • 2,733
  • 1
  • 14
  • 16