@@ -2,7 +2,8 @@ const resemble = require("resemblejs");
2
2
const fs = require ( 'fs' ) ;
3
3
const assert = require ( 'assert' ) ;
4
4
const mkdirp = require ( 'mkdirp' ) ;
5
- const getDirName = require ( 'path' ) . dirname ;
5
+ const path = require ( 'path' ) ;
6
+ const getDirName = path . dirname ;
6
7
7
8
/**
8
9
* Resemble.js helper class for CodeceptJS, this allows screen comparison
@@ -91,6 +92,25 @@ class ResembleHelper extends Helper {
91
92
else throw new Error ( "Method only works with Puppeteer" ) ;
92
93
}
93
94
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
+
94
114
/**
95
115
* Check Visual Difference for Base and Screenshot Image
96
116
* @param baseImage Name of the Base Image (Base Image path is taken from Configuration)
@@ -108,6 +128,9 @@ class ResembleHelper extends Helper {
108
128
}
109
129
110
130
const misMatch = await this . _fetchMisMatchPercentage ( baseImage , options ) ;
131
+
132
+ this . _addAttachment ( baseImage , misMatch , options . tolerance ) ;
133
+
111
134
this . debug ( "MisMatch Percentage Calculated is " + misMatch ) ;
112
135
assert ( misMatch <= options . tolerance , "MissMatch Percentage " + misMatch ) ;
113
136
}
@@ -133,6 +156,9 @@ class ResembleHelper extends Helper {
133
156
134
157
options . boundingBox = await this . _getBoundingBox ( selector ) ;
135
158
const misMatch = await this . _fetchMisMatchPercentage ( baseImage , options ) ;
159
+
160
+ this . _addAttachment ( baseImage , misMatch , options . tolerance ) ;
161
+
136
162
this . debug ( "MisMatch Percentage Calculated is " + misMatch ) ;
137
163
assert ( misMatch <= options . tolerance , "MissMatch Percentage " + misMatch ) ;
138
164
}
0 commit comments