@@ -64,6 +64,26 @@ const getScanData = (win, payload) => {
6464 } ) ;
6565} ;
6666
67+ const sendScanData = ( win , payload ) => {
68+ return new Promise ( ( resolve , reject ) => {
69+ const isHttpOrHttps = / ^ ( h t t p | h t t p s ) : $ / . test ( win . location . protocol ) ;
70+ if ( ! isHttpOrHttps ) return resolve ( ) ;
71+
72+ function onReceiveSummary ( event ) {
73+ win . document . removeEventListener ( "automation-custom-event" , onReceiveSummary ) ;
74+ resolve ( event . detail ) ;
75+ }
76+
77+ win . document . addEventListener ( "automation-custom-event" , onReceiveSummary ) ;
78+ const e = new CustomEvent ( "accessibility-extension-custom-event" , { detail : payload } ) ;
79+ win . document . dispatchEvent ( e ) ;
80+
81+ setTimeout ( ( ) => {
82+ resolve ( new Error ( 'automation-custom-event not received within timeout' ) ) ;
83+ } , 45000 ) ;
84+ } ) ;
85+ } ;
86+
6787async function processAccessibilityReport ( url ) {
6888 try {
6989 let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
@@ -99,28 +119,21 @@ async function processAccessibilityReport(url) {
99119 console . log ( "Logging response before sending to API:" , scanData ) ;
100120
101121 try {
122+
102123 let testId = Cypress . env ( "TEST_ID" ) || ""
124+ let reportAPI = Cypress . env ( "GENERATE_REPORT_API" ) || "http://localhost:43000/api/v1.0/cypress/generateAccessibilityReport"
103125 const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
104126 console . log ( "TestID is" , testId ) ;
105- const response = await fetch ( "http://localhost:43000/api/v1.0/cypress/generateAccessibilityReport" , {
106- method : "POST" ,
107- headers : {
108- "Content-Type" : "application/json"
109- } ,
110- body : JSON . stringify ( {
111- testId :testId ,
112- scanData : scanData ,
113- accessibilityReportPath :filePath
114- } )
115- } ) ;
116-
117- if ( ! response . ok ) {
118- console . log ( "HTTP error! Status" , response . status ) ;
119- return ;
120- }
121-
122- const result = await response . json ( ) ;
123- console . log ( "Accessibility Report Response:" , result ) ;
127+ const payloadToSend = {
128+ message : 'SEND_ACESSIBILITY_DATA' ,
129+ testId : testId ,
130+ scanData : scanData ,
131+ accessibilityReportPath :filePath ,
132+ api : reportAPI
133+ } ;
134+
135+ let response = await sendScanData ( payloadToSend ) ;
136+ console . log ( "Accessibility Report Response:" , response ) ;
124137 } catch ( err ) {
125138 console . error ( "Error while making api" , err ) ;
126139 }
0 commit comments