@@ -84,14 +84,16 @@ console.log('log', "debugging scan form command " + command.attributes.name);
8484cy . window ( ) . then ( ( win ) => {
8585 let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
8686 let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) || false ;
87- let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) || true ;
87+ let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) || false ;
8888
8989 const payloadToSend = {
9090 message : 'SET_CONFIG' ,
9191 wcagCriteria : wcagCriteriaValue ,
9292 bestPractice : bestPracticeValue ,
9393 needsReview : needsReviewValue
9494 }
95+
96+ console . log ( 'log' , "payload to send " + payloadToSend ) ;
9597 let testId = Cypress . env ( "TEST_ID" ) || ""
9698
9799 const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
@@ -142,4 +144,68 @@ cy.window().then((win) => {
142144Cypress . on ( 'command:end' , ( command ) => {
143145
144146return ;
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+ const payloadToSend = {
158+ message : 'SET_CONFIG' ,
159+ wcagCriteria : wcagCriteriaValue ,
160+ bestPractice : bestPracticeValue ,
161+ needsReview : needsReviewValue
162+ }
163+
164+ console . log ( 'log' , "payload to send " + payloadToSend ) ;
165+ let testId = Cypress . env ( "TEST_ID" ) || ""
166+
167+ const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
168+
169+ cy . wrap ( setScanConfig ( win , payloadToSend ) , { timeout : 30000 } ) . then ( ( res ) => {
170+ console . log ( 'logging config reponse' , res ) ;
171+
172+ const payload = {
173+ message : 'GET_LATEST_SCAN_DATA' ,
174+ }
175+
176+ cy . wrap ( getScanData ( win , payload ) , { timeout : 45000 } ) . then ( ( res ) => {
177+ LambdatestLog ( 'log' , "scanning data " ) ;
178+
179+
180+ cy . task ( 'initializeFile' , filePath ) . then ( ( filePath ) => {
181+ cy . readFile ( filePath , { log : true , timeout : 45000 } ) . then ( ( fileContent ) => {
182+ let resultsArray = [ { } ] ;
183+ console . log ( 'logging report' , res ) ;
184+ // If the file is not empty, parse the existing content
185+ if ( fileContent ) {
186+ try {
187+ resultsArray = JSON . parse ( JSON . stringify ( fileContent ) ) ;
188+ } catch ( e ) {
189+ console . log ( "parsing error for content " , fileContent )
190+ console . log ( 'Error parsing JSON file:' , e ) ;
191+ return ;
192+ }
193+ }
194+ console . log ( 'scanned data recieved is' , res . message ) ;
195+ if ( res . message == "GET_LATEST_SCAN_DATA" ) {
196+ // Append the new result
197+ resultsArray . push ( res ) ;
198+ console . log ( 'resultsarray logging' , resultsArray ) ;
199+ }
200+
201+ // Write the updated content back to the file
202+ cy . writeFile ( filePath , resultsArray , { log : true , timeout : 45000 } ) ;
203+ } ) ;
204+ } ) ;
205+ } ) ;
206+
207+ } ) ;
208+ } )
209+
210+
145211} )
0 commit comments