@@ -65,6 +65,70 @@ const getScanData = (win, payload) =>
6565
6666 } )
6767
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 . fileContent ) {
103+ try {
104+ resultsArray = JSON . parse ( JSON . stringify ( result . fileContent ) ) ;
105+ } catch ( e ) {
106+ console . log ( "parsing error for content " , result . fileContent )
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+ // Append the new result
119+ resultsArray . push ( res ) ;
120+ console . log ( 'resultsarray logging' , resultsArray ) ;
121+ }
122+
123+ // Write the updated content back to the file
124+ cy . writeFile ( filePath , resultsArray , { log : true , timeout : 45000 } ) ;
125+ } ) ;
126+ } ) ;
127+ } ) ;
128+
129+ } ) ;
130+ }
131+
68132Cypress . on ( 'command:start' , async ( command ) => {
69133 if ( ! command || ! command . attributes ) return ;
70134 if ( command . attributes . name == 'window' || command . attributes . name == 'then' || command . attributes . name == 'wrap' || command . attributes . name == 'wait' ) {
@@ -80,63 +144,9 @@ Cypress.on('command:start', async (command) => {
80144
81145
82146console . 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' ;
100147
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-
139- } ) ;
148+ cy . window ( ) . then ( ( win ) => {
149+ processAccessibilityReport ( win ) ;
140150} )
141151} )
142152
@@ -149,72 +159,14 @@ return;
149159
150160afterEach ( ( ) => {
151161console . log ( "after each hook" )
162+ let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
163+ if ( ! isAccessibilityLoaded ) {
164+ console . log ( 'log' , "accessibility not enabled " + isAccessibilityLoaded ) ;
165+ return ;
166+ }
152167 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- } )
168+ processAccessibilityReport ( win ) ;
169+ } )
218170
219171
220172} )
0 commit comments