Skip to content

Commit

Permalink
Fix issue when scenario has a dot at the end of name. Fix issue when …
Browse files Browse the repository at this point in the history
…screenshot is not find to avoid break Jenkins report
  • Loading branch information
samuelpampolini committed Jun 29, 2022
1 parent 84303fb commit 77dc80c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
});
}
}
Expand Down

0 comments on commit 77dc80c

Please sign in to comment.