@@ -12,6 +12,44 @@ const commandsToOverride = [
12
12
13
13
const commandsToWrap = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scroll' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
14
14
15
+ const performModifiedScan = ( originalFn , Subject , stateType , ...args ) => {
16
+ let customChaining = cy . wrap ( null ) . processAccessibilityReport ( ) ;
17
+ const changeSub = ( args , stateType , newSubject ) => {
18
+ if ( stateType !== 'parent' ) {
19
+ return [ newSubject , ...args . slice ( 1 ) ] ;
20
+ }
21
+ return args ;
22
+ }
23
+ const runCustomizedCommand = ( ) => {
24
+ if ( ! Subject ) {
25
+ let orgS1 , orgS2 , cypressCommandSubject = null ;
26
+ if ( ( orgS2 = ( orgS1 = cy ) . subject ) !== null && orgS2 !== void 0 ) {
27
+ cypressCommandSubject = orgS2 . call ( orgS1 ) ;
28
+ }
29
+ customChaining . then ( ( ) => cypressCommandSubject ) . then ( ( ) => { originalFn ( ...args ) } ) ;
30
+ } else {
31
+ let orgSC1 , orgSC2 , timeO1 , cypressCommandChain = null , setTimeout = null ;
32
+ if ( ( timeO1 = args . find ( arg => arg !== null && arg !== void 0 ? arg . timeout : null ) ) !== null && timeO1 !== void 0 ) {
33
+ setTimeout = timeO1 . timeout ;
34
+ }
35
+ if ( ( orgSC1 = ( orgSC2 = cy ) . subjectChain ) !== null && orgSC1 !== void 0 ) {
36
+ cypressCommandChain = orgSC1 . call ( orgSC2 ) ;
37
+ }
38
+ customChaining . performScanSubjectQuery ( cypressCommandChain , setTimeout ) . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...changeSub ( args , stateType , newSubject ) ) ) ;
39
+ }
40
+ }
41
+ runCustomizedCommand ( ) ;
42
+ }
43
+
44
+ Cypress . Commands . add ( 'processAccessibilityReport' , ( ) => {
45
+ try {
46
+ cy . window ( ) . then ( ( win ) => {
47
+ return cy . wrap ( processAccessibilityReport ( win ) , { timeout : 45000 } ) ;
48
+ } ) ;
49
+ } catch ( error ) {
50
+ console . log ( `Error in performing scan with error: ${ error . message } ` ) ;
51
+ }
52
+ } )
15
53
16
54
const setScanConfig = ( win , payload ) => {
17
55
return new Promise ( ( resolve , reject ) => {
@@ -76,7 +114,7 @@ const sendScanData = (win, payload) => {
76
114
} ) ;
77
115
} ;
78
116
79
- async function processAccessibilityReport ( url , windowNew ) {
117
+ const processAccessibilityReport = async ( windowNew ) => {
80
118
try {
81
119
let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
82
120
let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) === "true" ;
@@ -89,7 +127,7 @@ async function processAccessibilityReport(url,windowNew) {
89
127
needsReview : needsReviewValue
90
128
} ;
91
129
92
- console . log ( 'log' , "SET SCAN: Payload to send: for url: " , payloadToSend , url ) ;
130
+ console . log ( 'log' , "SET SCAN: Payload to send: for url: " , payloadToSend ) ;
93
131
try {
94
132
let setResult = await setScanConfig ( windowNew , payloadToSend ) ;
95
133
console . log ( 'SET SCAN: response:' , setResult ) ;
@@ -211,22 +249,18 @@ const overRideCommands = JSON.parse(Cypress.env("ACCESSIBILITY_OVERIDE_COMMANDS"
211
249
212
250
if ( overRideCommands ) {
213
251
commandsToOverride . forEach ( ( command ) => {
214
- Cypress . Commands . overwrite ( command , ( originalFn , url , options ) => {
252
+ Cypress . Commands . overwrite ( command , ( originalFn , ... args ) => {
215
253
let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
216
- if ( ! isAccessibilityLoaded ) {
217
- console . log ( 'log' , "Accessibility not enabled." ) ;
218
- return originalFn ( url , options ) ;
254
+ const state = cy . state ( 'current' ) , Subject = 'getSubjectFromChain' in cy ;
255
+ const stateName = state === null || state === void 0 ? void 0 : state . get ( 'name' ) ;
256
+ let stateType = null ;
257
+ if ( ! isAccessibilityLoaded || ( stateName && stateName !== command ) ) {
258
+ return originalFn ( ...args ) ;
219
259
}
220
- Cypress . log ( {
221
- name : command , // Display the passed command name
222
- displayName : `${ command } ` , // Change how it looks in the Cypress log
223
- message : url ,
224
- } ) ;
225
- return cy . window ( ) . then ( ( currentWindowNew ) => {
226
- return originalFn ( url , options ) . then ( ( ) => {
227
- return processAccessibilityReport ( url , currentWindowNew ) ;
228
- } ) ;
229
- } ) ;
260
+ if ( state !== null && state !== void 0 ) {
261
+ stateType = state . get ( 'type' ) ;
262
+ }
263
+ performModifiedScan ( originalFn , Subject , stateType , ...args ) ;
230
264
231
265
} ) ;
232
266
} ) ;
@@ -260,13 +294,16 @@ if (overRideCommands) {
260
294
return ;
261
295
}
262
296
cy . window ( ) . then ( ( win ) => {
263
- processAccessibilityReport ( win ) ;
297
+ oldprocessAccessibilityReport ( win ) ;
264
298
} )
265
299
266
300
267
301
} )
268
302
}
269
303
270
-
304
+ Cypress . Commands . addQuery ( 'performScanSubjectQuery' , function ( chaining , setTimeout ) {
305
+ this . set ( 'timeout' , setTimeout ) ;
306
+ return ( ) => cy . getSubjectFromChain ( chaining ) ;
307
+ } ) ;
271
308
272
309
0 commit comments