@@ -25,6 +25,11 @@ const defaultConfig = {
25
25
module . exports = function ( config ) {
26
26
// eslint-disable-next-line no-param-reassign
27
27
config = Object . assign ( defaultConfig , config ) ;
28
+ const plugin = { } ;
29
+
30
+ plugin . addScreenshot = ( file_path ) => {
31
+ addScreenshotToReport ( file_path ) ;
32
+ } ;
28
33
29
34
// Before suite starts, parse the feature file and set report feature position
30
35
event . dispatcher . on ( event . suite . before , ( suite ) => {
@@ -68,7 +73,10 @@ module.exports = function (config) {
68
73
} ) ;
69
74
70
75
event . dispatcher . on ( event . step . finished , ( step ) => {
71
- if ( step . helperMethod === 'saveScreenshot' ) addScreenshotToReport ( step ) ;
76
+ if ( step . helperMethod === 'saveScreenshot' ) {
77
+ const filePath = path . join ( global . output_dir , step . args [ 0 ] ) ;
78
+ addScreenshotToReport ( filePath ) ;
79
+ }
72
80
} ) ;
73
81
74
82
event . dispatcher . on ( event . step . comment , ( step ) => {
@@ -317,19 +325,18 @@ module.exports = function (config) {
317
325
return bddCheck ;
318
326
}
319
327
320
- function addScreenshotToReport ( step ) {
328
+ function addScreenshotToReport ( file_path ) {
321
329
if ( ! config . attachScreenshots ) return ;
322
- const filename = path . join ( global . output_dir , step . args [ 0 ] ) ;
323
330
try {
324
- const convertedImg = fs . readFileSync ( filename , 'base64' ) ;
331
+ const convertedImg = fs . readFileSync ( file_path , 'base64' ) ;
325
332
const screenshot = {
326
333
data : convertedImg ,
327
334
mime_type : 'image/png' ,
328
335
} ;
329
- output . log ( `[CucumberJsonReporter] Adding ${ filename } to:\n ${ JSON . stringify ( report . step ) } ` ) ;
336
+ output . log ( `[CucumberJsonReporter] Adding ${ file_path } to:\n ${ JSON . stringify ( report . step ) } ` ) ;
330
337
report . step . embeddings . push ( screenshot ) ;
331
338
} catch ( error ) {
332
- output . log ( `[CucumberJsonReporter] Couldn't add ${ filename } to:\n ${ JSON . stringify ( report . step ) } ` ) ;
339
+ output . log ( `[CucumberJsonReporter] Couldn't add ${ file_path } to:\n ${ JSON . stringify ( report . step ) } ` ) ;
333
340
}
334
341
}
335
342
@@ -342,4 +349,6 @@ module.exports = function (config) {
342
349
output . log ( `[CucumberJsonReporter] Adding comment "${ step } " to:\n ${ JSON . stringify ( report . step ) } ` ) ;
343
350
report . step . embeddings . push ( comment ) ;
344
351
}
352
+
353
+ return plugin ;
345
354
} ;
0 commit comments