@@ -148,20 +148,116 @@ async function processAccessibilityReport(url) {
148
148
}
149
149
}
150
150
151
- commandsToOverride . forEach ( ( command ) => {
152
- Cypress . Commands . overwrite ( command , ( originalFn , url , options ) => {
151
+ function oldprocessAccessibilityReport ( win ) {
152
+ let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
153
+ let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) || false ;
154
+ let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) || true ;
155
+ bestPracticeValue = bestPracticeValue == "true" ? true : false ;
156
+ needsReviewValue = needsReviewValue == "true" ? true : false ;
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 . task ( 'readFileIfExists' , filePath , { log : true , timeout : 45000 } ) . then ( ( result ) => {
182
+ let resultsArray = [ { } ] ;
183
+ console . log ( 'logging report' , res ) ;
184
+ // If the file is not empty, parse the existing content
185
+ if ( result . exists && result . content ) {
186
+ try {
187
+ resultsArray = JSON . parse ( result . content ) ;
188
+ } catch ( e ) {
189
+ console . log ( "parsing error for content " , result . content )
190
+ console . log ( 'Error parsing JSON file:' , e ) ;
191
+ return ;
192
+ }
193
+ } else if ( ! result . exists ) {
194
+ console . log ( 'accessibility file does not exist' ) ;
195
+ }
196
+ if ( res ) {
197
+ console . log ( 'scanned data recieved is' , res . message ) ;
198
+ }
199
+
200
+ if ( res && res . message == "GET_LATEST_SCAN_DATA" ) {
201
+ try {
202
+ // Append the new result
203
+ resultsArray . push ( res ) ;
204
+ console . log ( 'resultsarray logging' , resultsArray ) ;
205
+ } catch ( e ) {
206
+ console . log ( 'Error pushing issues to array:' , e ) ;
207
+ }
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
+ const overRideCommands = Cypress . env ( "ACCESSIBILITY_OVERIDE_COMMANDS" ) ;
220
+ if ( overRideCommands ) {
221
+ commandsToOverride . forEach ( ( command ) => {
222
+ Cypress . Commands . overwrite ( command , ( originalFn , url , options ) => {
223
+ let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
224
+ if ( ! isAccessibilityLoaded ) {
225
+ console . log ( 'log' , "Accessibility not enabled." ) ;
226
+ return originalFn ( url , options ) ;
227
+ }
228
+
229
+
230
+ return originalFn ( url , options ) . then ( async ( ) => {
231
+
232
+ await processAccessibilityReport ( url ) ;
233
+ } )
234
+
235
+ } ) ;
236
+ } ) ;
237
+ } else {
238
+ Cypress . on ( 'command:start' , async ( command ) => {
239
+ if ( ! command || ! command . attributes ) return ;
240
+ if ( command . attributes . name == 'window' || command . attributes . name == 'then' || command . attributes . name == 'wrap' || command . attributes . name == 'wait' ) {
241
+ return ;
242
+ }
243
+
244
+ if ( ! commandsToWrap . includes ( command . attributes . name ) ) return ;
153
245
let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
154
- if ( ! isAccessibilityLoaded ) {
155
- console . log ( 'log' , "Accessibility not enabled." ) ;
156
- return originalFn ( url , options ) ;
246
+ if ( ! isAccessibilityLoaded ) {
247
+ console . log ( 'log' , "accessibility not enabled " + isAccessibilityLoaded ) ;
248
+ return ;
157
249
}
158
250
159
251
160
- return originalFn ( url , options ) . then ( async ( ) => {
161
- await processAccessibilityReport ( url ) ;
252
+ console . log ( 'log' , "debugging scan form command " + command . attributes . name ) ;
253
+
254
+ cy . window ( ) . then ( ( win ) => {
255
+ oldprocessAccessibilityReport ( win ) ;
162
256
} )
257
+ } )
258
+
259
+ }
260
+
163
261
164
- } ) ;
165
- } ) ;
166
262
167
263
0 commit comments