Drop
Drop

Reputation: 450

How to attach screenshots after failed tests in JUnit report in Cypress.io

Im trying to generate Cypress.io test report with screenshots after failed tests, but Im unable to attach screens to final xml. Screenshots are being created in cypress dir, but they are not attached to final .xml.

Ive tried different combinations of setting but nothing seems to work. Also there are no errors during test run connected to report generation or attachments. I also tried running it using Chrome and Electron but results were the same. Im using Cypress version: 3.4.1

cypress.json:

{
  "baseUrl": "https://www.google.com/",
  "reporter": "junit",
  "reporterOptions": {
    "mochaFile": "tests/test-output-[hash].xml",
    "toConsole": true,
    "attachments": true
    },
    "video": false
}

sampleTests.spec.js:

describe('My First Test', function() {
  it('Does not do much!', function() {
    cy.visit('/');
    expect(true).to.equal(true)
  })

  it('Does not do much too!', function() {
    cy.visit('/');
    expect(true).to.equal(false)
  })
})

Actual results: Screenshots are being created in dir cypress\screenshots, but they are not attached to .xml report

Expected results: Screenshots are being attached to reports.

What am I missing?

Upvotes: 3

Views: 5720

Answers (1)

L. Copley
L. Copley

Reputation: 145

Inside the test block or in the afterEach() of the test, you need to define the path to the attachment.

this.test.attachments = ['/absolut/path/to/file.png'];

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

Upvotes: 2

Related Questions