@@ -34,7 +34,7 @@ class ResembleHelper extends Helper {
34
34
* @param image
35
35
* @param diffImage
36
36
* @param options
37
- * @returns {Promise<any | never > }
37
+ * @returns {Promise<resolve | reject > }
38
38
*/
39
39
async _compareImages ( image , diffImage , options ) {
40
40
const image1 = this . baseFolder + image ;
@@ -76,17 +76,12 @@ class ResembleHelper extends Helper {
76
76
}
77
77
resolve ( data ) ;
78
78
if ( data . misMatchPercentage >= tolerance ) {
79
- mkdirp ( getDirName ( this . diffFolder + diffImage ) , function ( err ) {
80
- if ( err ) return cb ( err ) ;
81
- } ) ;
82
- fs . writeFile ( this . diffFolder + diffImage + '.png' , data . getBuffer ( ) , ( err , data ) => {
83
- if ( err ) {
84
- throw new Error ( this . err ) ;
85
- } else {
86
- const diffImagePath = path . join ( process . cwd ( ) , this . diffFolder + diffImage + '.png' ) ;
87
- this . debug ( "Diff Image File Saved to: " + diffImagePath ) ;
88
- }
79
+ mkdirp ( getDirName ( this . diffFolder + diffImage ) , function ( error ) {
80
+ if ( error ) return cb ( error ) ;
89
81
} ) ;
82
+ fs . writeFileSync ( this . diffFolder + diffImage + '.png' , data . getBuffer ( ) ) ;
83
+ const diffImagePath = path . join ( process . cwd ( ) , this . diffFolder + diffImage + '.png' ) ;
84
+ this . debug ( "Diff Image File Saved to: " + diffImagePath ) ;
90
85
}
91
86
}
92
87
} ) ;
@@ -179,9 +174,9 @@ class ResembleHelper extends Helper {
179
174
Key : `output/${ baseImage } ` ,
180
175
Body : base64data
181
176
} ;
182
- s3 . upload ( params , ( uerr , data ) => {
183
- if ( uerr ) throw uerr ;
184
- console . log ( `Screenshot Image uploaded successfully at ${ data . Location } ` ) ;
177
+ s3 . upload ( params , ( uErr , uData ) => {
178
+ if ( uErr ) throw uErr ;
179
+ console . log ( `Screenshot Image uploaded successfully at ${ uData . Location } ` ) ;
185
180
} ) ;
186
181
} ) ;
187
182
fs . readFile ( this . diffFolder + "Diff_" + baseImage , ( err , data ) => {
@@ -193,9 +188,9 @@ class ResembleHelper extends Helper {
193
188
Key : `diff/Diff_${ baseImage } ` ,
194
189
Body : base64data
195
190
} ;
196
- s3 . upload ( params , ( uerr , data ) => {
197
- if ( uerr ) throw uerr ;
198
- console . log ( `Diff Image uploaded successfully at ${ data . Location } ` )
191
+ s3 . upload ( params , ( uErr , uData ) => {
192
+ if ( uErr ) throw uErr ;
193
+ console . log ( `Diff Image uploaded successfully at ${ uData . Location } ` )
199
194
} ) ;
200
195
}
201
196
} ) ;
@@ -209,9 +204,9 @@ class ResembleHelper extends Helper {
209
204
Key : `base/${ baseImage } ` ,
210
205
Body : base64data
211
206
} ;
212
- s3 . upload ( params , ( uerr , data ) => {
213
- if ( uerr ) throw uerr ;
214
- console . log ( `Base Image uploaded at ${ data . Location } ` )
207
+ s3 . upload ( params , ( uErr , uData ) => {
208
+ if ( uErr ) throw uErr ;
209
+ console . log ( `Base Image uploaded at ${ uData . Location } ` )
215
210
} ) ;
216
211
}
217
212
} ) ;
@@ -241,7 +236,7 @@ class ResembleHelper extends Helper {
241
236
Bucket : bucketName ,
242
237
Key : `base/${ baseImage } `
243
238
} ;
244
- return new Promise ( ( resolve , reject ) => {
239
+ return new Promise ( ( resolve ) => {
245
240
s3 . getObject ( params , ( err , data ) => {
246
241
if ( err ) console . error ( err ) ;
247
242
console . log ( this . baseFolder + baseImage ) ;
@@ -258,32 +253,7 @@ class ResembleHelper extends Helper {
258
253
* @returns {Promise<void> }
259
254
*/
260
255
async seeVisualDiff ( baseImage , options ) {
261
- if ( options == undefined ) {
262
- options = { } ;
263
- options . tolerance = 0 ;
264
- }
265
-
266
- const awsC = this . config . aws ;
267
-
268
- if ( awsC !== undefined && options . prepareBaseImage === false ) {
269
- await this . _download ( awsC . accessKeyId , awsC . secretAccessKey , awsC . region , awsC . bucketName , baseImage ) ;
270
- }
271
-
272
- if ( options . prepareBaseImage !== undefined && options . prepareBaseImage ) {
273
- await this . _prepareBaseImage ( baseImage ) ;
274
- }
275
-
276
- const misMatch = await this . _fetchMisMatchPercentage ( baseImage , options ) ;
277
-
278
- this . _addAttachment ( baseImage , misMatch , options . tolerance ) ;
279
-
280
- if ( awsC !== undefined ) {
281
- let ifUpload = options . prepareBaseImage === false ? false : true ;
282
- await this . _upload ( awsC . accessKeyId , awsC . secretAccessKey , awsC . region , awsC . bucketName , baseImage , ifUpload )
283
- }
284
-
285
- this . debug ( "MisMatch Percentage Calculated is " + misMatch ) ;
286
- assert ( misMatch <= options . tolerance , "MissMatch Percentage " + misMatch ) ;
256
+ await this . _assertVisualDiff ( undefined , baseImage , options ) ;
287
257
}
288
258
289
259
/**
@@ -295,8 +265,11 @@ class ResembleHelper extends Helper {
295
265
* @returns {Promise<void> }
296
266
*/
297
267
async seeVisualDiffForElement ( selector , baseImage , options ) {
268
+ await this . _assertVisualDiff ( selector , baseImage , options ) ;
269
+ }
298
270
299
- if ( options == undefined ) {
271
+ async _assertVisualDiff ( selector , baseImage , options ) {
272
+ if ( ! options ) {
300
273
options = { } ;
301
274
options . tolerance = 0 ;
302
275
}
@@ -311,14 +284,16 @@ class ResembleHelper extends Helper {
311
284
await this . _prepareBaseImage ( baseImage ) ;
312
285
}
313
286
314
- options . boundingBox = await this . _getBoundingBox ( selector ) ;
287
+ if ( selector ) {
288
+ options . boundingBox = await this . _getBoundingBox ( selector ) ;
289
+ }
290
+
315
291
const misMatch = await this . _fetchMisMatchPercentage ( baseImage , options ) ;
316
292
317
293
this . _addAttachment ( baseImage , misMatch , options . tolerance ) ;
318
294
319
295
if ( awsC !== undefined ) {
320
- let ifUpload = options . prepareBaseImage === false ? false : true ;
321
- await this . _upload ( awsC . accessKeyId , awsC . secretAccessKey , awsC . region , awsC . bucketName , baseImage , ifUpload )
296
+ await this . _upload ( awsC . accessKeyId , awsC . secretAccessKey , awsC . region , awsC . bucketName , baseImage , options . prepareBaseImage )
322
297
}
323
298
324
299
this . debug ( "MisMatch Percentage Calculated is " + misMatch ) ;
@@ -390,6 +365,10 @@ class ResembleHelper extends Helper {
390
365
size = await helper . browser . getElementSize ( selector ) ;
391
366
}
392
367
368
+ if ( ! size ) {
369
+ throw new Error ( "Cannot get element size!" ) ;
370
+ }
371
+
393
372
const bottom = size . height + location . y ;
394
373
const right = size . width + location . x ;
395
374
const boundingBox = {
0 commit comments