@@ -34,7 +34,7 @@ class ResembleHelper extends Helper {
3434 * @param image
3535 * @param diffImage
3636 * @param options
37- * @returns {Promise<any | never > }
37+ * @returns {Promise<resolve | reject > }
3838 */
3939 async _compareImages ( image , diffImage , options ) {
4040 const image1 = this . baseFolder + image ;
@@ -76,17 +76,12 @@ class ResembleHelper extends Helper {
7676 }
7777 resolve ( data ) ;
7878 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 ) ;
8981 } ) ;
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 ) ;
9085 }
9186 }
9287 } ) ;
@@ -179,9 +174,9 @@ class ResembleHelper extends Helper {
179174 Key : `output/${ baseImage } ` ,
180175 Body : base64data
181176 } ;
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 } ` ) ;
185180 } ) ;
186181 } ) ;
187182 fs . readFile ( this . diffFolder + "Diff_" + baseImage , ( err , data ) => {
@@ -193,9 +188,9 @@ class ResembleHelper extends Helper {
193188 Key : `diff/Diff_${ baseImage } ` ,
194189 Body : base64data
195190 } ;
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 } ` )
199194 } ) ;
200195 }
201196 } ) ;
@@ -209,9 +204,9 @@ class ResembleHelper extends Helper {
209204 Key : `base/${ baseImage } ` ,
210205 Body : base64data
211206 } ;
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 } ` )
215210 } ) ;
216211 }
217212 } ) ;
@@ -241,7 +236,7 @@ class ResembleHelper extends Helper {
241236 Bucket : bucketName ,
242237 Key : `base/${ baseImage } `
243238 } ;
244- return new Promise ( ( resolve , reject ) => {
239+ return new Promise ( ( resolve ) => {
245240 s3 . getObject ( params , ( err , data ) => {
246241 if ( err ) console . error ( err ) ;
247242 console . log ( this . baseFolder + baseImage ) ;
@@ -258,32 +253,7 @@ class ResembleHelper extends Helper {
258253 * @returns {Promise<void> }
259254 */
260255 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 ) ;
287257 }
288258
289259 /**
@@ -295,8 +265,11 @@ class ResembleHelper extends Helper {
295265 * @returns {Promise<void> }
296266 */
297267 async seeVisualDiffForElement ( selector , baseImage , options ) {
268+ await this . _assertVisualDiff ( selector , baseImage , options ) ;
269+ }
298270
299- if ( options == undefined ) {
271+ async _assertVisualDiff ( selector , baseImage , options ) {
272+ if ( ! options ) {
300273 options = { } ;
301274 options . tolerance = 0 ;
302275 }
@@ -311,14 +284,16 @@ class ResembleHelper extends Helper {
311284 await this . _prepareBaseImage ( baseImage ) ;
312285 }
313286
314- options . boundingBox = await this . _getBoundingBox ( selector ) ;
287+ if ( selector ) {
288+ options . boundingBox = await this . _getBoundingBox ( selector ) ;
289+ }
290+
315291 const misMatch = await this . _fetchMisMatchPercentage ( baseImage , options ) ;
316292
317293 this . _addAttachment ( baseImage , misMatch , options . tolerance ) ;
318294
319295 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 )
322297 }
323298
324299 this . debug ( "MisMatch Percentage Calculated is " + misMatch ) ;
@@ -390,6 +365,10 @@ class ResembleHelper extends Helper {
390365 size = await helper . browser . getElementSize ( selector ) ;
391366 }
392367
368+ if ( ! size ) {
369+ throw new Error ( "Cannot get element size!" ) ;
370+ }
371+
393372 const bottom = size . height + location . y ;
394373 const right = size . width + location . x ;
395374 const boundingBox = {
0 commit comments