@@ -4,6 +4,9 @@ const LambdatestLog = (message) => {
44 cy . task ( 'lambdatest_log' , message ) ;
55}
66
7+ let globalScreenshots = null ;
8+ const captureScreenshotEnabled = Cypress . env ( "CAPTURE_SCREENSHOT_ENABLED" ) === "true" ;
9+
710const commandsToOverride = [
811 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' ,
912 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scrollTo' ,
@@ -40,7 +43,43 @@ const performNewLambdaScan = (originalFn, Subject, stateType, ...args) => {
4043 if ( subjectChainFn !== null && subjectChainFn !== void 0 ) {
4144 cypressCommandChain = subjectChainFn . call ( cy ) ;
4245 }
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+ }
4483 }
4584 }
4685 runCustomizedChainingCommand ( ) ;
@@ -124,12 +163,14 @@ const processAccessibilityReport = async (windowNew) => {
124163 let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
125164 let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) === "true" ;
126165 let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) !== "false" ; // Default to true
166+ let captureScreenshotEnabled = Cypress . env ( "CAPTURE_SCREENSHOT_ENABLED" ) === "true" ;
127167
128168 const payloadToSend = {
129169 message : 'SET_CONFIG' ,
130170 wcagCriteria : wcagCriteriaValue ,
131171 bestPractice : bestPracticeValue ,
132- needsReview : needsReviewValue
172+ needsReview : needsReviewValue ,
173+ captureScreenshotEnabled : captureScreenshotEnabled
133174 } ;
134175
135176 console . log ( 'log' , "SET SCAN: Payload to send: " , payloadToSend ) ;
@@ -146,6 +187,25 @@ const processAccessibilityReport = async (windowNew) => {
146187 const payload = { message : 'GET_LATEST_SCAN_DATA' } ;
147188 scanData = await getScanData ( windowNew , payload ) ;
148189 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+ }
149209 } catch ( err ) {
150210 console . error ( "GET SCAN:Error while setting scan" , err ) ;
151211 return ;
0 commit comments