0

I am using following code to attach the snapshot in json

import cucumber.api.java.After;
    @After
public void tearDown(Scenario scenario) {

    if (scenario.isFailed()) {
        final byte[] screenshot = ((TakesScreenshot) driver)
                    .getScreenshotAs(OutputType.BYTES);
        scenario.embed(screenshot, "image/png"); //stick it in the report
    }
}

and to generate I am using following code:

reportBuilder = new ReportBuilder(jsonReports, reportDirectory, "", buildNumber, buildProject, skippedFails, undefinedFails, flashCharts, runWithJenkins, false, "", false);

But somehow I am getting snapshots attached twice and sometimes they do not work, When i click on snapshot 1 it opens snapshot 2 and vice-versa.

Navdeep Singh
  • 699
  • 1
  • 10
  • 25

1 Answers1

0

I believe you don't need to use ReportBuilder. I have exact @After tag like you and I am able to attach screenshots fine (locally in target/html-reports and in jenkins as well). I use it in conjunction with the cucumber reporting jenkins plugin. Below is my config screenshot.

enter image description here

nilesh
  • 14,131
  • 7
  • 65
  • 79
  • The real problem exists in the code execution, I have 2 stepDefs, when i execute the scenario for 1st then ideally "After" should be called from 1st stepDef only, But its being called from 2nd too, Utlimately after every Scenario "After" method from every StepDefinition is getting called. I do not know why this is happening. This scene results to 2 snapshots for a single scenario – Navdeep Singh Jun 12 '14 at 04:03
  • you can tag your features and mark `@After` tag to run only for that specific tag, like `@After("@onlyRunForThisFeature")`. – nilesh Jun 12 '14 at 13:11
  • any hint why after method is being called on feature that does not belong to them – Navdeep Singh Jun 12 '14 at 13:21
  • An `@After` without specific tag will be executed for all features by default – nilesh Jun 12 '14 at 13:35