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
You get access to these methods:
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
}
}