@@ -6,41 +6,30 @@ const browserStackLog = (message) => {
6
6
}
7
7
8
8
const commandsToWrap = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scroll' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
9
+ // scroll is not a default function in cypress.
9
10
const commandToOverwrite = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
11
+
12
+ /*
13
+ Overrriding the cypress commands to perform Accessibility Scan before Each command
14
+ - runCutomizedCommand is handling both the cases of subject available in cypress original command
15
+ and chaning available from original cypress command.
16
+ */
10
17
const performModifiedScan = ( originalFn , Subject , stateType , ...args ) => {
11
18
let customChaining = cy . wrap ( null ) . performScan ( ) ;
12
- function changeSub ( args , stateType , newSubject ) {
19
+ const changeSub = ( args , stateType , newSubject ) => {
13
20
if ( stateType !== 'parent' ) {
14
21
return [ newSubject , ...args . slice ( 1 ) ] ;
15
22
}
16
23
return args ;
17
24
}
18
- function runCutomizedCommand ( ) {
25
+ const runCutomizedCommand = ( ) => {
19
26
if ( ! Subject ) {
20
- let orgS1 , orgS2 , cypressCommandSubject ;
21
- if ( ( orgS2 = ( orgS1 = cy ) . subject ) !== null && orgS2 !== void 0 ) {
22
- cypressCommandSubject = orgS2 . call ( orgS1 ) ;
23
- }
24
- else {
25
- cypressCommandSubject = null ;
26
- }
27
- customChaining . then ( ( ) => cypressCommandSubject ) . then ( ( ) => { originalFn ( ...args ) } ) ;
28
- }
29
- else {
30
- let orgSC1 , orgSC2 , timeO1 , cypressCommandChain , setTimeout ;
31
- if ( ( timeO1 = args . find ( arg => arg !== null && arg !== void 0 ? arg . timeout : null ) ) !== null && timeO1 !== void 0 ) {
32
- setTimeout = timeO1 . timeout ;
33
- }
34
- else {
35
- setTimeout = null ;
36
- }
37
- if ( ( orgSC1 = ( orgSC2 = cy ) . subjectChain ) !== null && orgSC1 !== void 0 ) {
38
- cypressCommandChain = orgSC1 . call ( orgSC2 ) ;
39
- }
40
- else {
41
- cypressCommandChain = null ;
42
- }
43
- customChaining . performScanSubjectQuery ( cypressCommandChain , setTimeout ) . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...changeSub ( args , stateType , newSubject ) ) ) ;
27
+ let cypressCommandSubject = ( cy . subject ?. call ( cy ) ) ?? null ;
28
+ customChaining . then ( ( ) => cypressCommandSubject ) . then ( ( ) => { originalFn ( ...args ) ; } ) ;
29
+ } else {
30
+ let setTimeout = args . find ( arg => arg ?. timeout ) ?. timeout ?? null ;
31
+ let cypressCommandChain = ( cy . subjectChain ?. call ( cy ) ) ?? null ;
32
+ customChaining . performScanSubjectQuery ( cypressCommandChain , setTimeout ) . then ( { timeout : 10000 } , newSubject => originalFn ( ...changeSub ( args , stateType , newSubject ) ) ) ;
44
33
}
45
34
}
46
35
runCutomizedCommand ( ) ;
@@ -50,8 +39,7 @@ const performScan = (win, payloadToSend) =>
50
39
new Promise ( async ( resolve , reject ) => {
51
40
const isHttpOrHttps = / ^ ( h t t p | h t t p s ) : $ / . test ( win . location . protocol ) ;
52
41
if ( ! isHttpOrHttps ) {
53
- resolve ( ) ;
54
- return ;
42
+ return resolve ( ) ;
55
43
}
56
44
57
45
function findAccessibilityAutomationElement ( ) {
@@ -64,16 +52,14 @@ new Promise(async (resolve, reject) => {
64
52
const intervalID = setInterval ( async ( ) => {
65
53
if ( count > retryCount ) {
66
54
clearInterval ( intervalID ) ;
67
- reject (
55
+ return reject (
68
56
new Error (
69
57
"Accessibility Automation Scanner is not ready on the page."
70
58
)
71
59
) ;
72
- return ;
73
60
} else if ( findAccessibilityAutomationElement ( ) ) {
74
61
clearInterval ( intervalID ) ;
75
- resolve ( "Scanner set" ) ;
76
- return ;
62
+ return resolve ( "Scanner set" ) ;
77
63
} else {
78
64
count += 1 ;
79
65
}
@@ -84,8 +70,7 @@ new Promise(async (resolve, reject) => {
84
70
function startScan ( ) {
85
71
function onScanComplete ( ) {
86
72
win . removeEventListener ( "A11Y_SCAN_FINISHED" , onScanComplete ) ;
87
- resolve ( ) ;
88
- return ;
73
+ return resolve ( ) ;
89
74
}
90
75
91
76
win . addEventListener ( "A11Y_SCAN_FINISHED" , onScanComplete ) ;
@@ -99,8 +84,7 @@ new Promise(async (resolve, reject) => {
99
84
waitForScannerReadiness ( )
100
85
. then ( startScan )
101
86
. catch ( async ( err ) => {
102
- resolve ( "Scanner is not ready on the page after multiple retries. performscan" ) ;
103
- return ;
87
+ return resolve ( "Scanner is not ready on the page after multiple retries. performscan" ) ;
104
88
} ) ;
105
89
}
106
90
} )
@@ -109,8 +93,7 @@ const getAccessibilityResultsSummary = (win) =>
109
93
new Promise ( ( resolve ) => {
110
94
const isHttpOrHttps = / ^ ( h t t p | h t t p s ) : $ / . test ( window . location . protocol ) ;
111
95
if ( ! isHttpOrHttps ) {
112
- resolve ( ) ;
113
- return ;
96
+ return resolve ( ) ;
114
97
}
115
98
116
99
function findAccessibilityAutomationElement ( ) {
@@ -123,16 +106,14 @@ new Promise((resolve) => {
123
106
const intervalID = setInterval ( ( ) => {
124
107
if ( count > retryCount ) {
125
108
clearInterval ( intervalID ) ;
126
- reject (
109
+ return reject (
127
110
new Error (
128
111
"Accessibility Automation Scanner is not ready on the page."
129
112
)
130
113
) ;
131
- return ;
132
114
} else if ( findAccessibilityAutomationElement ( ) ) {
133
115
clearInterval ( intervalID ) ;
134
- resolve ( "Scanner set" ) ;
135
- return ;
116
+ return resolve ( "Scanner set" ) ;
136
117
} else {
137
118
count += 1 ;
138
119
}
@@ -143,8 +124,7 @@ new Promise((resolve) => {
143
124
function getSummary ( ) {
144
125
function onReceiveSummary ( event ) {
145
126
win . removeEventListener ( "A11Y_RESULTS_SUMMARY" , onReceiveSummary ) ;
146
- resolve ( event . detail ) ;
147
- return ;
127
+ return resolve ( event . detail ) ;
148
128
}
149
129
150
130
win . addEventListener ( "A11Y_RESULTS_SUMMARY" , onReceiveSummary ) ;
@@ -158,8 +138,7 @@ new Promise((resolve) => {
158
138
waitForScannerReadiness ( )
159
139
. then ( getSummary )
160
140
. catch ( ( err ) => {
161
- resolve ( ) ;
162
- return ;
141
+ return resolve ( ) ;
163
142
} ) ;
164
143
}
165
144
} )
@@ -168,8 +147,7 @@ const getAccessibilityResults = (win) =>
168
147
new Promise ( ( resolve ) => {
169
148
const isHttpOrHttps = / ^ ( h t t p | h t t p s ) : $ / . test ( window . location . protocol ) ;
170
149
if ( ! isHttpOrHttps ) {
171
- resolve ( ) ;
172
- return ;
150
+ return resolve ( ) ;
173
151
}
174
152
175
153
function findAccessibilityAutomationElement ( ) {
@@ -182,16 +160,14 @@ new Promise((resolve) => {
182
160
const intervalID = setInterval ( ( ) => {
183
161
if ( count > retryCount ) {
184
162
clearInterval ( intervalID ) ;
185
- reject (
163
+ return reject (
186
164
new Error (
187
165
"Accessibility Automation Scanner is not ready on the page."
188
166
)
189
167
) ;
190
- return ;
191
168
} else if ( findAccessibilityAutomationElement ( ) ) {
192
169
clearInterval ( intervalID ) ;
193
- resolve ( "Scanner set" ) ;
194
- return ;
170
+ return resolve ( "Scanner set" ) ;
195
171
} else {
196
172
count += 1 ;
197
173
}
@@ -202,8 +178,7 @@ new Promise((resolve) => {
202
178
function getResults ( ) {
203
179
function onReceivedResult ( event ) {
204
180
win . removeEventListener ( "A11Y_RESULTS_RESPONSE" , onReceivedResult ) ;
205
- resolve ( event . detail ) ;
206
- return ;
181
+ return resolve ( event . detail ) ;
207
182
}
208
183
209
184
win . addEventListener ( "A11Y_RESULTS_RESPONSE" , onReceivedResult ) ;
@@ -217,8 +192,7 @@ new Promise((resolve) => {
217
192
waitForScannerReadiness ( )
218
193
. then ( getResults )
219
194
. catch ( ( err ) => {
220
- resolve ( ) ;
221
- return ;
195
+ return resolve ( ) ;
222
196
} ) ;
223
197
}
224
198
} ) ;
@@ -242,16 +216,14 @@ new Promise( (resolve, reject) => {
242
216
const intervalID = setInterval ( async ( ) => {
243
217
if ( count > retryCount ) {
244
218
clearInterval ( intervalID ) ;
245
- reject (
219
+ return reject (
246
220
new Error (
247
221
"Accessibility Automation Scanner is not ready on the page."
248
222
)
249
223
) ;
250
- return ;
251
224
} else if ( findAccessibilityAutomationElement ( ) ) {
252
225
clearInterval ( intervalID ) ;
253
- resolve ( "Scanner set" ) ;
254
- return ;
226
+ return resolve ( "Scanner set" ) ;
255
227
} else {
256
228
count += 1 ;
257
229
}
@@ -261,8 +233,7 @@ new Promise( (resolve, reject) => {
261
233
262
234
function saveResults ( ) {
263
235
function onResultsSaved ( event ) {
264
- resolve ( ) ;
265
- return ;
236
+ return resolve ( ) ;
266
237
}
267
238
win . addEventListener ( "A11Y_RESULTS_SAVED" , onResultsSaved ) ;
268
239
const e = new CustomEvent ( "A11Y_SAVE_RESULTS" , {
@@ -277,14 +248,12 @@ new Promise( (resolve, reject) => {
277
248
waitForScannerReadiness ( )
278
249
. then ( saveResults )
279
250
. catch ( async ( err ) => {
280
- resolve ( "Scanner is not ready on the page after multiple retries. after run" ) ;
281
- return ;
251
+ return resolve ( "Scanner is not ready on the page after multiple retries. after run" ) ;
282
252
} ) ;
283
253
}
284
254
} catch ( error ) {
285
255
browserStackLog ( `Error in saving results with error: ${ error . message } ` ) ;
286
- resolve ( ) ;
287
- return ;
256
+ return resolve ( ) ;
288
257
}
289
258
290
259
} )
@@ -348,7 +317,7 @@ afterEach(() => {
348
317
let shouldScanTestForAccessibility = shouldScanForAccessibility ( attributes ) ;
349
318
if ( ! shouldScanTestForAccessibility ) return cy . wrap ( { } ) ;
350
319
351
- cy . wrap ( performScan ( win ) , { timeout : 30000 } ) . then ( ( ) => {
320
+ cy . wrap ( performScan ( win ) , { timeout : 10000 } ) . then ( ( ) => {
352
321
try {
353
322
let os_data ;
354
323
if ( Cypress . env ( "OS" ) ) {
@@ -379,7 +348,7 @@ afterEach(() => {
379
348
}
380
349
} ;
381
350
browserStackLog ( `Saving accessibility test results` ) ;
382
- cy . wrap ( saveTestResults ( win , payloadToSend ) , { timeout : 30000 } ) . then ( ( ) => {
351
+ cy . wrap ( saveTestResults ( win , payloadToSend ) , { timeout : 10000 } ) . then ( ( ) => {
383
352
browserStackLog ( `Saved accessibility test results` ) ;
384
353
} )
385
354
@@ -400,7 +369,7 @@ Cypress.Commands.add('performScan', () => {
400
369
}
401
370
cy . window ( ) . then ( async ( win ) => {
402
371
browserStackLog ( `Performing accessibility scan` ) ;
403
- cy . wrap ( performScan ( win ) , { timeout :40000 } ) ;
372
+ cy . wrap ( performScan ( win ) , { timeout :10000 } ) ;
404
373
} ) ;
405
374
} catch ( error ) {
406
375
browserStackLog ( `Error in performing scan with error: ${ error . message } ` ) ;
0 commit comments