cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.41k stars 3.14k forks source link

Attachment path injected into the test object is not passed to the reporter #3143

Open bkosse opened 5 years ago

bkosse commented 5 years ago

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
kuceb commented 5 years ago

@bkosse since we expect the test context to adhere to a strict schema, we explicitly construct the final context before passing it to reporters, picking only the values we expect off of the mocha context.

However, we are working on a feature to allow you to attach arbitrary data onto a ctx object that can be passed onto reporters, and should be in an issue soon

https://github.com/cypress-io/cypress/blob/4b368830faca8794859abd8972f0c67a5bdd5839/packages/server/lib/reporter.coffee#L66

poplevente commented 4 years ago

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

jennifer-shehane commented 3 years ago

This issue is still in the 'proposal' stage, which means no work has been done on this issue as of today, so we do not have an estimate on when this will be delivered.

Kodziak commented 3 years ago

Any progress?

iakovmarkov commented 3 years ago

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

colinodell commented 3 years ago

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

max-mayorov commented 3 years ago

Hi, How's is the progress on this issue. We would really like to see it happen... Cheers!

kchojhu commented 2 years ago

Just another comment to promote this request. Gitlab CI CD supports Junit format reports and it would be amazing to see screenshot attachments

timstapl commented 2 years ago

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

jogelin commented 1 year ago

Same here, trying to attach screenshots to the Test object provided to mocha-junit-reporter but impossible to configure attachments as it is described here: image

jonascarlbaum commented 1 year ago

Still no progress here?

Would be really handy.

alecmestroni commented 8 months ago

Hello Guys, tired of waiting I just create this library for this purpose. Is able to attach screenshots into the report and import them into xray

https://www.npmjs.com/package/cypress-xray-junit-reporter

Its the first version, further development requests are appreciated.

valeria-chernikova commented 1 month ago

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.

sebastiansterk commented 1 month ago

Any progress on this? Still an issue in 13.10.0