@@ -4,6 +4,9 @@ const LambdatestLog = (message) => {
4
4
cy . task ( 'lambdatest_log' , message ) ;
5
5
}
6
6
7
+ let globalScreenshots = null ;
8
+ const captureScreenshotEnabled = Cypress . env ( "CAPTURE_SCREENSHOT_ENABLED" ) === "true" ;
9
+
7
10
const commandsToOverride = [
8
11
'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' ,
9
12
'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scrollTo' ,
@@ -40,7 +43,43 @@ const performNewLambdaScan = (originalFn, Subject, stateType, ...args) => {
40
43
if ( subjectChainFn !== null && subjectChainFn !== void 0 ) {
41
44
cypressCommandChain = subjectChainFn . call ( cy ) ;
42
45
}
43
- cycustomChaining . performScanSubjectQuery ( cypressCommandChain , setTimeout ) . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...updateSubj ( args , stateType , newSubject ) ) ) ;
46
+
47
+ if ( captureScreenshotEnabled ) {
48
+ cy . log ( 'Starting performScanSubjectQuery' ) ;
49
+ cycustomChaining
50
+ . performScanSubjectQuery ( cypressCommandChain , setTimeout )
51
+ . then ( { timeout : 30000 } , ( newSubject ) => {
52
+ const updatedArgs = updateSubj ( args , stateType , newSubject ) ;
53
+ const screenshotId = crypto . randomUUID ( ) ;
54
+ const screenshotName = 'accessibility-screenshot-' + screenshotId ;
55
+ cy . screenshot ( screenshotName , { capture : 'fullPage' } ) ;
56
+ cy . task ( 'convertScreenshotToBase64' , `cypress/screenshots/${ Cypress . spec . name } /${ screenshotName } .png` ) . then ( ( result ) => {
57
+ if ( result && result . base64 ) {
58
+ const imageUrl = `data:image/png;base64,${ result . base64 } ` ;
59
+ const imageResolution = result . resolution ;
60
+ // Create screenshots array
61
+ const screenshots = [
62
+ {
63
+ image_url : imageUrl ,
64
+ image_resolution : `${ imageResolution . width } x${ imageResolution . height } ` ,
65
+ screenshotId : screenshotId
66
+ }
67
+ ] ;
68
+ // Store globally for use in processAccessibilityReport
69
+ globalScreenshots = screenshots ;
70
+
71
+ cy . task ( 'deleteFile' , `cypress/screenshots/${ Cypress . spec . name } /${ screenshotName } .png` ) . then ( ( _ ) => {
72
+ } ) ;
73
+ } else {
74
+ cy . log ( 'Failed to process screenshot' ) ;
75
+ }
76
+ } ) ;
77
+ const result = originalFn ( ...updatedArgs ) ;
78
+ return result ;
79
+ } ) ;
80
+ } else {
81
+ cycustomChaining . performScanSubjectQuery ( cypressCommandChain , setTimeout ) . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...updateSubj ( args , stateType , newSubject ) ) ) ;
82
+ }
44
83
}
45
84
}
46
85
runCustomizedChainingCommand ( ) ;
@@ -124,12 +163,14 @@ const processAccessibilityReport = async (windowNew) => {
124
163
let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
125
164
let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) === "true" ;
126
165
let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) !== "false" ; // Default to true
166
+ let captureScreenshotEnabled = Cypress . env ( "CAPTURE_SCREENSHOT_ENABLED" ) === "true" ;
127
167
128
168
const payloadToSend = {
129
169
message : 'SET_CONFIG' ,
130
170
wcagCriteria : wcagCriteriaValue ,
131
171
bestPractice : bestPracticeValue ,
132
- needsReview : needsReviewValue
172
+ needsReview : needsReviewValue ,
173
+ captureScreenshotEnabled : captureScreenshotEnabled
133
174
} ;
134
175
135
176
console . log ( 'log' , "SET SCAN: Payload to send: " , payloadToSend ) ;
@@ -146,6 +187,25 @@ const processAccessibilityReport = async (windowNew) => {
146
187
const payload = { message : 'GET_LATEST_SCAN_DATA' } ;
147
188
scanData = await getScanData ( windowNew , payload ) ;
148
189
LambdatestLog ( "GET SCAN:LambdaTest Accessibility: Scanning URL" ) ;
190
+ if ( captureScreenshotEnabled ) {
191
+ if ( scanData && scanData . data && scanData . data . length > 0 && globalScreenshots ) {
192
+ const firstDataItem = scanData . data [ 0 ] ;
193
+ if ( firstDataItem . events && firstDataItem . events . length > 0 ) {
194
+ const firstEvent = firstDataItem . events [ 0 ] ;
195
+ if ( firstEvent . issues && firstEvent . issues . length > 0 ) {
196
+ // Update screenshotId with the actual screenshotId
197
+ globalScreenshots [ 0 ] . screenshotId = firstEvent . issues [ 0 ] . screenshotId ;
198
+ }
199
+ }
200
+ for ( let i = 0 ; i < scanData . data . length ; i ++ ) {
201
+ if ( scanData . data [ i ] . screenshots && Array . isArray ( scanData . data [ i ] . screenshots ) ) {
202
+ scanData . data [ i ] . screenshots = globalScreenshots ;
203
+ break ;
204
+ }
205
+ }
206
+ }
207
+ globalScreenshots = null ;
208
+ }
149
209
} catch ( err ) {
150
210
console . error ( "GET SCAN:Error while setting scan" , err ) ;
151
211
return ;
0 commit comments