Skip to content

How to use Relative path instead of Absolute path for failed screenshot due to cypress-image-snapshot  #260

@787681277

Description

@787681277

Describe the bug
A clear and concise description of what the bug is.

Cannot see failed screenshot in mochareports/report.html after run testing in pipeline

Because failed screenshot use Absolute path, and redundant path "/script" is displayed after run testing in pipeline:
"See diff for details: /scripts/cypress/snapshots/chrome/tab/tab.component.cy.ts/diff_output/activeIndex-1.diff.png"

Code Reproduce
Link to repo where the issue can reliably be reproduced:

//Inject cypress-image-snapshot diff images to Mochawesome reports
const addContext = require('mochawesome/addContext');
Cypress.on('test:after:run', (test, runnable) => {
if(test.state === 'failed') {
let screenshot;
screenshot = ${Cypress.config('screenshotsFolder')}/${Cypress.spec.name}/${runnable.parent.title} -- ${test.title} (failed).png;
if(test.err.message.includes('See diff')) {
// If the test failed due to cypress-image-snapshot the message will always be the same and the plugin gives you in the message the url of the path
screenshot = test.err.parsedStack[1].message.replace('See diff for details: ', '');
}
addContext({test}, {
title: 'Image',
value: screenshot
});
}
})

Expected behavior
A clear and concise description of what you expected to happen.

Use Relative path for failed screenshots due to cypress-image-snapshot , the failed screenshot can be seen after run testing in piepline

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):
Screen Shot 2022-11-22 at 18 43 24

Platform
mac
mochawesome version
mocha (or other test library) version
Node version
node 14.20.0

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions