diff --git a/index.js b/index.js index 53265de..543843f 100644 --- a/index.js +++ b/index.js @@ -5,17 +5,24 @@ afterEach(() => { const stepResult = testState.runTests[testState.currentScenario.name][testState.currentStep]; if (stepResult?.status === "failed") { - const screenshotFileName = `${testState.feature.name} -- ${testState.currentScenario.name} (failed).png`; + const scenarioName = testState.currentScenario.name.endsWith('.') ? + testState.currentScenario.name.substring(0, testState.currentScenario.name.length - 1) : + testState.currentScenario.name; + + const screenshotFileName = `${testState.feature.name} -- ${scenarioName} (failed).png`; + cy.readFile( `${screenshotsFolder}/${Cypress.spec.name}/${screenshotFileName}`, "base64" ).then((imgData) => { - stepResult.attachment = { - data: imgData, - media: { type: "image/png" }, - index: testState.currentStep, - testCase: testState.formatTestCase(testState.currentScenario), - }; + if(imgData) { + stepResult.attachment = { + data: imgData, + media: { type: "image/png" }, + index: testState.currentStep, + testCase: testState.formatTestCase(testState.currentScenario), + }; + } }); } }