Junit @Before/@After is not executing in cucumber bdd | Selenium Forum
M
Posted on 28/12/2016
Sir,
i have 1 feature & 4 scenarios in it.
Have implemented extentreports for this.
i forcefully make some step of scenario:[b:2jwxf7w1]Best?ll h?mtning[/b:2jwxf7w1] fail & i want to take screenshot & want it in my extent report

Issue:[b:2jwxf7w1]Even though scenario fails , screenshot is never attached in report.[/b:2jwxf7w1]
i have my .java file attached
[b:2jwxf7w1]Could you please suggest..[/b:2jwxf7w1]


My Junit annotations are as follows:


@Before
public void before(Scenario scenario) {
this.scenario = scenario;
}

@After
public void embedScreenshot(Scenario scenario) {
if (scenario.isFailed()) {
try {
byte[] screenshot = ((TakesScreenshot) selenium.w)
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
System.out.println("-----------SCREENSHOT TAKEN---------------------");
} catch (Exception e) {
e.printStackTrace();
}
}
}

References:
https://selenisolutions.wordpress.com/2016/07/28/cucumber-java-reporting-with-extent-reports/
https://github.com/email2vimalraj/CucumberExtentReporter
https://github.com/anshooarora/extentreports-java/issues/415