@@ -65,6 +65,74 @@ const getScanData = (win, payload) =>
65
65
66
66
} )
67
67
68
+ function processAccessibilityReport ( win ) {
69
+ let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
70
+ let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) || false ;
71
+ let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) || true ;
72
+ bestPracticeValue = bestPracticeValue == "true" ? true : false ;
73
+ needsReviewValue = needsReviewValue == "true" ? true : false ;
74
+ const payloadToSend = {
75
+ message : 'SET_CONFIG' ,
76
+ wcagCriteria : wcagCriteriaValue ,
77
+ bestPractice : bestPracticeValue ,
78
+ needsReview : needsReviewValue
79
+ }
80
+
81
+ console . log ( 'log' , "payload to send " + payloadToSend ) ;
82
+ let testId = Cypress . env ( "TEST_ID" ) || ""
83
+
84
+ const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
85
+
86
+ cy . wrap ( setScanConfig ( win , payloadToSend ) , { timeout : 30000 } ) . then ( ( res ) => {
87
+ console . log ( 'logging config reponse' , res ) ;
88
+
89
+ const payload = {
90
+ message : 'GET_LATEST_SCAN_DATA' ,
91
+ }
92
+
93
+ cy . wrap ( getScanData ( win , payload ) , { timeout : 45000 } ) . then ( ( res ) => {
94
+ LambdatestLog ( 'log' , "scanning data " ) ;
95
+
96
+
97
+ cy . task ( 'initializeFile' , filePath ) . then ( ( filePath ) => {
98
+ cy . task ( 'readFileIfExists' , filePath , { log : true , timeout : 45000 } ) . then ( ( result ) => {
99
+ let resultsArray = [ { } ] ;
100
+ console . log ( 'logging report' , res ) ;
101
+ // If the file is not empty, parse the existing content
102
+ if ( result . exists && result . content ) {
103
+ try {
104
+ resultsArray = JSON . parse ( result . content ) ;
105
+ } catch ( e ) {
106
+ console . log ( "parsing error for content " , result . content )
107
+ console . log ( 'Error parsing JSON file:' , e ) ;
108
+ return ;
109
+ }
110
+ } else if ( ! result . exists ) {
111
+ console . log ( 'accessibility file does not exist' ) ;
112
+ }
113
+ if ( res ) {
114
+ console . log ( 'scanned data recieved is' , res . message ) ;
115
+ }
116
+
117
+ if ( res && res . message == "GET_LATEST_SCAN_DATA" ) {
118
+ try {
119
+ // Append the new result
120
+ resultsArray . push ( res ) ;
121
+ console . log ( 'resultsarray logging' , resultsArray ) ;
122
+ } catch ( e ) {
123
+ console . log ( 'Error pushing issues to array:' , e ) ;
124
+ }
125
+ }
126
+
127
+ // Write the updated content back to the file
128
+ cy . writeFile ( filePath , resultsArray , { log : true , timeout : 45000 } ) ;
129
+ } ) ;
130
+ } ) ;
131
+ } ) ;
132
+
133
+ } ) ;
134
+ }
135
+
68
136
Cypress . on ( 'command:start' , async ( command ) => {
69
137
if ( ! command || ! command . attributes ) return ;
70
138
if ( command . attributes . name == 'window' || command . attributes . name == 'then' || command . attributes . name == 'wrap' || command . attributes . name == 'wait' ) {
@@ -80,63 +148,9 @@ Cypress.on('command:start', async (command) => {
80
148
81
149
82
150
console . log ( 'log' , "debugging scan form command " + command . attributes . name ) ;
83
- cy . window ( ) . then ( ( win ) => {
84
- let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
85
- let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) || false ;
86
- let needsReviewValue = Cypress . env ( "NEEDS_REVIEW" ) || true ;
87
- bestPracticeValue = bestPracticeValue == "true" ? true : false ;
88
- needsReviewValue = needsReviewValue == "true" ? true : false ;
89
- const payloadToSend = {
90
- message : 'SET_CONFIG' ,
91
- wcagCriteria : wcagCriteriaValue ,
92
- bestPractice : bestPracticeValue ,
93
- needsReview : needsReviewValue
94
- }
95
-
96
- console . log ( 'log' , "payload to send " + payloadToSend ) ;
97
- let testId = Cypress . env ( "TEST_ID" ) || ""
98
-
99
- const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
100
-
101
- cy . wrap ( setScanConfig ( win , payloadToSend ) , { timeout : 30000 } ) . then ( ( res ) => {
102
- console . log ( 'logging config reponse' , res ) ;
103
-
104
- const payload = {
105
- message : 'GET_LATEST_SCAN_DATA' ,
106
- }
107
-
108
- cy . wrap ( getScanData ( win , payload ) , { timeout : 45000 } ) . then ( ( res ) => {
109
- LambdatestLog ( 'log' , "scanning data " ) ;
110
-
111
-
112
- cy . task ( 'initializeFile' , filePath ) . then ( ( filePath ) => {
113
- cy . readFile ( filePath , { log : true , timeout : 45000 } ) . then ( ( fileContent ) => {
114
- let resultsArray = [ { } ] ;
115
- console . log ( 'logging report' , res ) ;
116
- // If the file is not empty, parse the existing content
117
- if ( fileContent ) {
118
- try {
119
- resultsArray = JSON . parse ( JSON . stringify ( fileContent ) ) ;
120
- } catch ( e ) {
121
- console . log ( "parsing error for content " , fileContent )
122
- console . log ( 'Error parsing JSON file:' , e ) ;
123
- return ;
124
- }
125
- }
126
- console . log ( 'scanned data recieved is' , res . message ) ;
127
- if ( res . message == "GET_LATEST_SCAN_DATA" ) {
128
- // Append the new result
129
- resultsArray . push ( res ) ;
130
- console . log ( 'resultsarray logging' , resultsArray ) ;
131
- }
132
-
133
- // Write the updated content back to the file
134
- cy . writeFile ( filePath , resultsArray , { log : true , timeout : 45000 } ) ;
135
- } ) ;
136
- } ) ;
137
- } ) ;
138
151
139
- } ) ;
152
+ cy . window ( ) . then ( ( win ) => {
153
+ processAccessibilityReport ( win ) ;
140
154
} )
141
155
} )
142
156
@@ -149,72 +163,14 @@ return;
149
163
150
164
afterEach ( ( ) => {
151
165
console . log ( "after each hook" )
166
+ let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
167
+ if ( ! isAccessibilityLoaded ) {
168
+ console . log ( 'log' , "accessibility not enabled " + isAccessibilityLoaded ) ;
169
+ return ;
170
+ }
152
171
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
- } )
172
+ processAccessibilityReport ( win ) ;
173
+ } )
218
174
219
175
220
176
} )
0 commit comments