Is it possible to get scenario inside the step in Cucumber?

855 Views Asked by At

I need to make screenshot inside the step on specific place. It means not on @BeforeStep nor on @AfterStep. I need to call

// public void someStep(Scenario scenario)  // This does not work

public void someStep()
{
    page.openUrl();
    scenario.attach(screenshot(), "image/png", fileName1);
    page.doSomething();
    scenario.attach(screenshot(), "image/png", fileName2);
    page.doSomethingElse();
}

But I am not able to get current scenario related to the step execution. Is it possible or not? I tried to call it like someStep(Scenarion scenario) but it throws an error.

2

There are 2 best solutions below

1
On

If you want access to the scenario object, your best bet is an AfterStep hook. However this is not supported in all flavours of cucumber. Your best bet is to check the docs or API documentation for your language

0
On