cypress icon indicating copy to clipboard operation
cypress copied to clipboard

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

Open bkosse opened this issue 6 years ago • 10 comments

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

bkosse avatar Jan 16 '19 14:01 bkosse

@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

kuceb avatar Jan 16 '19 16:01 kuceb

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

poplevente avatar Apr 15 '20 08:04 poplevente

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.

jennifer-shehane avatar Aug 19 '20 10:08 jennifer-shehane

Any progress?

Kodziak avatar Apr 12 '21 13:04 Kodziak

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

iakovmarkov avatar May 04 '21 07:05 iakovmarkov

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

colinodell avatar Jun 11 '21 18:06 colinodell

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

max-mayorov avatar Jun 24 '21 14:06 max-mayorov

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

kchojhu avatar Jul 24 '21 01:07 kchojhu

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

timstapl avatar Feb 02 '22 18:02 timstapl

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

jogelin avatar Sep 20 '22 06:09 jogelin

Still no progress here?

Would be really handy.

jonascarlbaum avatar Mar 05 '23 21:03 jonascarlbaum

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.

alecmestroni avatar Oct 31 '23 10:10 alecmestroni

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.

valeria-chernikova avatar May 23 '24 14:05 valeria-chernikova

Any progress on this? Still an issue in 13.10.0

sebastiansterk avatar May 28 '24 06:05 sebastiansterk