@@ -2,7 +2,8 @@ const resemble = require("resemblejs");
22const fs = require ( 'fs' ) ;
33const assert = require ( 'assert' ) ;
44const mkdirp = require ( 'mkdirp' ) ;
5- const getDirName = require ( 'path' ) . dirname ;
5+ const path = require ( 'path' ) ;
6+ const getDirName = path . dirname ;
67
78/**
89 * Resemble.js helper class for CodeceptJS, this allows screen comparison
@@ -91,6 +92,25 @@ class ResembleHelper extends Helper {
9192 else throw new Error ( "Method only works with Puppeteer" ) ;
9293 }
9394
95+ /**
96+ * This method attaches image attachments of the base, screenshot and diff to the allure reporter when the mismatch exceeds tolerance.
97+ * @param baseImage
98+ * @param misMatch
99+ * @param tolerance
100+ * @returns {Promise<void> }
101+ */
102+
103+ async _addAttachment ( baseImage , misMatch , tolerance ) {
104+ const allure = codeceptjs . container . plugins ( 'allure' ) ;
105+ const diffImage = "Diff_" + baseImage . split ( "." ) [ 0 ] + ".png" ;
106+
107+ if ( allure && misMatch >= tolerance ) {
108+ allure . addAttachment ( 'Base Image' , fs . readFileSync ( path . join ( this . config . baseFolder , baseImage ) ) , 'image/png' ) ;
109+ allure . addAttachment ( 'Screenshot Image' , fs . readFileSync ( path . join ( this . config . screenshotFolder , baseImage ) ) , 'image/png' ) ;
110+ allure . addAttachment ( 'Diff Image' , fs . readFileSync ( path . join ( this . config . diffFolder , diffImage ) ) , 'image/png' ) ;
111+ }
112+ }
113+
94114 /**
95115 * Check Visual Difference for Base and Screenshot Image
96116 * @param baseImage Name of the Base Image (Base Image path is taken from Configuration)
@@ -108,6 +128,9 @@ class ResembleHelper extends Helper {
108128 }
109129
110130 const misMatch = await this . _fetchMisMatchPercentage ( baseImage , options ) ;
131+
132+ this . _addAttachment ( baseImage , misMatch , options . tolerance ) ;
133+
111134 this . debug ( "MisMatch Percentage Calculated is " + misMatch ) ;
112135 assert ( misMatch <= options . tolerance , "MissMatch Percentage " + misMatch ) ;
113136 }
@@ -133,6 +156,9 @@ class ResembleHelper extends Helper {
133156
134157 options . boundingBox = await this . _getBoundingBox ( selector ) ;
135158 const misMatch = await this . _fetchMisMatchPercentage ( baseImage , options ) ;
159+
160+ this . _addAttachment ( baseImage , misMatch , options . tolerance ) ;
161+
136162 this . debug ( "MisMatch Percentage Calculated is " + misMatch ) ;
137163 assert ( misMatch <= options . tolerance , "MissMatch Percentage " + misMatch ) ;
138164 }
0 commit comments