Skip to content

Commit

Permalink
fix: DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Jun 28, 2023
1 parent 71a96f2 commit dcd9109
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/plugin/screenshotOnFail.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ module.exports = function (config) {
event.dispatcher.on(event.test.failed, (test) => {
recorder.add('screenshot of failed test', async () => {
let fileName = clearString(test.title);
// This prevent data driven to be included in the failed screenshot file name
const dataType = 'image/png';
// This prevents data driven to be included in the failed screenshot file name
if (fileName.indexOf('{') !== -1) {
fileName = fileName.substr(0, (fileName.indexOf('{') - 3)).trim();
}
Expand Down Expand Up @@ -106,13 +107,13 @@ module.exports = function (config) {

const allureReporter = Container.plugins('allure');
if (allureReporter) {
allureReporter.addAttachment('Main session - Last Seen Screenshot', fs.readFileSync(path.join(global.output_dir, fileName)), 'image/png');
allureReporter.addAttachment('Main session - Last Seen Screenshot', fs.readFileSync(path.join(global.output_dir, fileName)), dataType);

if (helper.activeSessionName) {
for (const sessionName in helper.sessionPages) {
const screenshotFileName = `${sessionName}_${fileName}`;
test.artifacts[`${sessionName.replace(/ /g, '_')}_screenshot`] = path.join(global.output_dir, screenshotFileName);
allureReporter.addAttachment(`${sessionName} - Last Seen Screenshot`, fs.readFileSync(path.join(global.output_dir, screenshotFileName)), 'image/png');
allureReporter.addAttachment(`${sessionName} - Last Seen Screenshot`, fs.readFileSync(path.join(global.output_dir, screenshotFileName)), dataType);
}
}
}
Expand Down

0 comments on commit dcd9109

Please sign in to comment.