1- const fs = require ( "fs" )
21
32const LambdatestLog = ( message ) => {
43 if ( ! Cypress . env ( 'LAMBDATEST_LOGS' ) ) return ;
@@ -93,6 +92,8 @@ cy.window().then((win) => {
9392 bestPractice : bestPracticeValue ,
9493 needsReview : needsReviewValue
9594 }
95+
96+ console . log ( 'log' , "payload to send " + payloadToSend ) ;
9697 let testId = Cypress . env ( "TEST_ID" ) || ""
9798
9899 const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
@@ -143,4 +144,77 @@ cy.window().then((win) => {
143144Cypress . on ( 'command:end' , ( command ) => {
144145
145146return ;
147+ } )
148+
149+
150+ afterEach ( ( ) => {
151+ console . log ( "after each hook" )
152+ cy . window ( ) . then ( ( win ) => {
153+ let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
154+ let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) || false ;
155+ let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) || false ;
156+
157+ bestPracticeValue = bestPracticeValue == "true" ? true : false ;
158+ needsReviewValue = needsReviewValue == "true" ? true : false ;
159+
160+ let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
161+ if ( ! isAccessibilityLoaded ) {
162+ console . log ( 'log' , "accessibility not enabled " + isAccessibilityLoaded ) ;
163+ return ;
164+ }
165+
166+ const payloadToSend = {
167+ message : 'SET_CONFIG' ,
168+ wcagCriteria : wcagCriteriaValue ,
169+ bestPractice : bestPracticeValue ,
170+ needsReview : needsReviewValue
171+ }
172+
173+ console . log ( 'log' , "payload to send " + payloadToSend ) ;
174+ let testId = Cypress . env ( "TEST_ID" ) || ""
175+
176+ const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
177+
178+ cy . wrap ( setScanConfig ( win , payloadToSend ) , { timeout : 30000 } ) . then ( ( res ) => {
179+ console . log ( 'logging config reponse' , res ) ;
180+
181+ const payload = {
182+ message : 'GET_LATEST_SCAN_DATA' ,
183+ }
184+
185+ cy . wrap ( getScanData ( win , payload ) , { timeout : 45000 } ) . then ( ( res ) => {
186+ LambdatestLog ( 'log' , "scanning data " ) ;
187+
188+
189+ cy . task ( 'initializeFile' , filePath ) . then ( ( filePath ) => {
190+ cy . readFile ( filePath , { log : true , timeout : 45000 } ) . then ( ( fileContent ) => {
191+ let resultsArray = [ { } ] ;
192+ console . log ( 'logging report' , res ) ;
193+ // If the file is not empty, parse the existing content
194+ if ( fileContent ) {
195+ try {
196+ resultsArray = JSON . parse ( JSON . stringify ( fileContent ) ) ;
197+ } catch ( e ) {
198+ console . log ( "parsing error for content " , fileContent )
199+ console . log ( 'Error parsing JSON file:' , e ) ;
200+ return ;
201+ }
202+ }
203+ console . log ( 'scanned data recieved is' , res . message ) ;
204+ if ( res . message == "GET_LATEST_SCAN_DATA" ) {
205+ // Append the new result
206+ resultsArray . push ( res ) ;
207+ console . log ( 'resultsarray logging' , resultsArray ) ;
208+ }
209+
210+ // Write the updated content back to the file
211+ cy . writeFile ( filePath , resultsArray , { log : true , timeout : 45000 } ) ;
212+ } ) ;
213+ } ) ;
214+ } ) ;
215+
216+ } ) ;
217+ } )
218+
219+
146220} )
0 commit comments