Created
July 16, 2020 07:10
-
-
Save przemuh/08e29454ec276019009648552433b4eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import addContext from "mochawesome/addContext"; | |
Cypress.Screenshot.defaults({ | |
// Disable default screenshot on fail because we want to change the filename | |
screenshotOnRunFailure: false, | |
}); | |
function generateScreenshotName(test) { | |
const MAX_SPEC_NAME_LENGTH = 220; | |
return [ | |
test.fullTitle().slice(0, MAX_SPEC_NAME_LENGTH), | |
" (failed) ", | |
test.hookName, | |
] | |
.filter(Boolean) | |
.join("") | |
.trim(); | |
} | |
afterEach(function() { | |
if (this.currentTest.state === "failed") { | |
cy.screenshot(generateScreenshotName(this.currentTest), { | |
capture: "runner", | |
}); | |
} | |
}); | |
Cypress.on("test:after:run", (test, runnable) => { | |
addContext({ test }, `${generateScreenshotName(runnable)}.png`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment