0

I am currently implementing integration of Cucumber/Jira/Xray. I am using json formatter plugin from cucumber to generate test report and xray maven plugin to import test result in Jira/Xray. See code below:

@ConfigurationParameter(
    key = "cucumber.plugin",
    value = "json:target/cucumber-reports/cucumber.json"
)
public class RunnerPttas {
}

Things are working fine as long as I don't have any attachments which I want to attach to test executions in Jira. I am using following code to attach screenshots to the scenario:

@AfterStep
    public void takeScreenshots(Scenario scenario) throws IOException {
        byte[] data = Files.readAllBytes(Paths.get(screenshotPath+"evidence.png"));;// get screenshot from somewhere
        scenario.attach(data, "image/png", "Evidence");
    }

Now I see the screenshot is added to the after object inside each step in the scenario like below:

[
  {
    "elements": [
      {
        ...
        "steps": [
          {
            ...
            "after": [
              {
                "embeddings": [
                  {
                    "data": "<BASE64_ENCODED_FILE>"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
]

Now checking at the official xray documentation, the attachment needs to come under step object directly (and not wrapped inside after object), see below:

[
  {
    "elements": [
      {
        ...
        "steps": [
          {
            ...
            "embeddings": [
              {
                "data": "<BASE64_ENCODED_FILE>"
              }
            ]
          }
        ]
      }
    ]
  }
]

Is it something I could configure the json formatter plugin to produce the right format? Currently imported results do not show any attachment in the Jira Test Execution ticket. I believe its not an xray maven plugin issue, its just the format produced is not correct. Any help would be greatly appreciated.

Marit
  • 2,399
  • 18
  • 27
Obaid Maroof
  • 1,523
  • 2
  • 19
  • 40

1 Answers1

1

Attachments are supported at scenario level hooks or at step level hooks. Therefore, the following format is fine

 "elements": [
  {
    "steps": [
      {
        "result": {
          "duration": 440463000,
          "status": "passed"
        },
        "line": 6,
        "name": "user is on the welcome page",
        "match": {
          "location": "webdemo.StepDefinitions.user_is_on_the_welcome_page()"
        },
        "after": [
          {
            "embeddings": [
              {
                "data": "iVBOR...

After importing the results you should have something like this: Xray datacenter screenshot with evidence

Please not that the attachments are seen on the Test Run execution details page; maybe that's your issue in fact. To go there, you need to use that shortcut available from the Test Execution page, next to the corresponding Test.

enter image description here

In this case I'm using this to run the tests:

mvn clean compile test -Dcucumber.plugin="json:report.json" -Dcucumber.features="features/"

I have here a full working example. I've updated it with a code snippet of the @AfterStep hook.

Note: This works both for Xray on Jira server/datacenter or Xray on Jira cloud.

Sérgio
  • 1,777
  • 2
  • 10
  • 12