cancel
Showing results for 
Search instead for 
Did you mean: 

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

Camo
Occasional Contributor

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

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.

 

Thanks for any help.

1 REPLY 1

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

Hello,

It looks like you are using Cucumber-jvm

 

If so, I think using DI as explained in the following may help: https://cucumber.io/docs/cucumber/state/

I think that would allow you to bring the attach method inside your steps as part of your glue code

New Here?
Join us and watch the welcome video: