@@ -64,6 +64,26 @@ const getScanData = (win, payload) => {
64
64
} ) ;
65
65
} ;
66
66
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
+
67
87
async function processAccessibilityReport ( url ) {
68
88
try {
69
89
let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
@@ -99,28 +119,21 @@ async function processAccessibilityReport(url) {
99
119
console . log ( "Logging response before sending to API:" , scanData ) ;
100
120
101
121
try {
122
+
102
123
let testId = Cypress . env ( "TEST_ID" ) || ""
124
+ let reportAPI = Cypress . env ( "GENERATE_REPORT_API" ) || "http://localhost:43000/api/v1.0/cypress/generateAccessibilityReport"
103
125
const filePath = Cypress . env ( "ACCESSIBILITY_REPORT_PATH" ) || 'cypress/results/accessibilityReport_' + testId + '.json' ;
104
126
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 ) ;
124
137
} catch ( err ) {
125
138
console . error ( "Error while making api" , err ) ;
126
139
}
0 commit comments