cypress: Attachment path injected into the test object is not passed to the reporter

Current behavior:

New feature in mocha-junit-reporter allows for an attachment path to be included in the report output file. To achieve this the attachment path is injected into the test object:

it ('should include attachment', function () {
  this.test.attachments = ['/absolut/path/to/file.png'];
});

(as described here: https://github.com/michaelleeallen/mocha-junit-reporter#attachments)

Currently Cypress does not pass the injected attachment in the test object passed to the reporter:

{
  "title": "should include attachment",
  "pending": false,
  "type": "test",
  "body": "function () {\n  this.test.attachments = ['/absolut/path/to/file.png'];\n}",
  "duration": 45,
  "state": "passed",
  "parent": "#<Suite>",
  "id": "r2",
  "wallClockStartedAt": "2019-01-16T14:36:45.039Z",
  "timings": {
    "lifecycle": 40,
    "test": {
      "fnDuration": 1,
      "afterFnDuration": 3
    }
  },
  "speed": "medium"
}

Desired behavior:

Cypress passes the injected attachment in the test object passed to the reporter:

{
  "title": "should include attachment",
  "attachments": '/absolut/path/to/file.png',
  "pending": false,
  "type": "test",
  "body": "function () {\n  this.test.attachments = ['/absolut/path/to/file.png'];\n}",
  "duration": 45,
  "state": "passed",
  "parent": "#<Suite>",
  "id": "r2",
  "wallClockStartedAt": "2019-01-16T14:36:45.039Z",
  "timings": {
    "lifecycle": 40,
    "test": {
      "fnDuration": 1,
      "afterFnDuration": 3
    }
  },
  "speed": "medium"
}

Steps to reproduce: (app code and test code)

Run test:

it ('should include attachment', function () {
  this.test.attachments = ['/absolut/path/to/file.png'];
});

And view the object that is passed to the reporter.

Versions

cypress: 3.1.4

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 43
  • Comments: 17 (2 by maintainers)

Most upvoted comments

@Bkucera @jennifer-shehane is there any way using attachments in the report file? (junit) was anything added since this issue was opened?

Still no progress here?

Would be really handy.

Is there anything the community can do to help get this implemented? I’d love this in our CI/CD.

Any progress on this? Still an issue in 13.10.0

GitLab just added support for showing JUnit screenshot attachments in merge requests. Hopefully that encourages more interest in this proposed feature.

@jennifer-shehane can this please be prioritized now that both GitLab and Azure Devops support this? A workaround would also be acceptable, but so far nobody managed to find one.

I was trying to add this event as following but never works

// cypress.config.js under setupNodeEvents
      on("after:screenshot", function (details) {
        // Attach screenshot file to test case
        this.test.attachments = details.path;
      });

#https://www.npmjs.com/package/mocha-junit-reporter#attachments

#https://docs.cypress.io/api/plugins/after-screenshot-api After a screenshot is taken, you can get details about the screenshot via the after:screenshot plugin event. This event is called when a screenshot is taken with cy.screenshot() or as a result of a test failure. The event is called after the screenshot image is written to disk.

This feature would be very useful. Azure DevOps recently made some improvements to the Publish Test Results task in Azure Pipelines. This task now supports file attachments when publishing test results from a JUnit report.

Any movement on this? I’m also running cypress tests in gitlab CICD and would love to include screenshots in my JUnit reports.