Skip to content

Commit

Permalink
fix: screenshot title
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Dec 26, 2023
1 parent 95fa3e1 commit 1440f07
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ module.exports = (config) => {
await sendLogToRP({ tempId: stepObj.tempId, level: 'ERROR', message: `[FAILED STEP] - ${(step.err.stack ? step.err.stack : JSON.stringify(step.err))}` });
debug(`Attaching screenshot & error to failed step`);

const screenshot = await attachScreenshot();
const screenshot = await attachScreenshot(`${clearString(test.testTitle)}.failed.png`);
await sendLogToRP({
tempId: stepObj.tempId, level: 'debug', message: 'Last seen screenshot', screenshotData: screenshot,
});
} else if (stepObj.status === 'failed' && step.helper.currentRunningTest.err) {
await sendLogToRP({ tempId: stepObj.tempId, level: 'ERROR', message: `[FAILED STEP] - ${step.helper.currentRunningTest.err}` });
debug(`Attaching screenshot & error to failed step`);

const screenshot = await attachScreenshot();
const screenshot = await attachScreenshot(`${clearString(test.testTitle)}.failed.png`);
await sendLogToRP({
tempId: stepObj.tempId, level: 'debug', message: 'Last seen screenshot', screenshotData: screenshot,
});
Expand Down Expand Up @@ -420,25 +420,29 @@ module.exports = (config) => {
return `${config.endpoint.split('api')[0]}ui/#${config.projectName}/launches/all/${launch[0].id}`;
}

async function attachScreenshot() {
async function attachScreenshot(fileName) {
if (!helper) return undefined;
let content;

const fileName = `${rpClient.helpers.now()}.png`;
try {
await helper.saveScreenshot(fileName);
} catch (err) {
output.error(`Couldn't save screenshot`);
return undefined;
if (!fileName) {
fileName = `${rpClient.helpers.now()}_failed.png`;
try {
await helper.saveScreenshot(fileName);
content = fs.readFileSync(path.join(global.output_dir, fileName));
fs.unlinkSync(path.join(global.output_dir, fileName));
} catch (err) {
output.error('Couldn\'t save screenshot');
return undefined;
}
} else {
content = fs.readFileSync(path.join(global.output_dir, fileName));
}

const content = fs.readFileSync(path.join(global.output_dir, fileName));
fs.unlinkSync(path.join(global.output_dir, fileName));

return {
name: 'failed.png',
name: fileName,
type: 'image/png',
content,
}
};
}

async function finishLaunch() {
Expand Down

0 comments on commit 1440f07

Please sign in to comment.