@@ -12,6 +12,49 @@ 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 performNewLambdaScan = ( originalFn , Subject , stateType , ...args ) => {
16
+ let cycustomChaining = cy . wrap ( null ) . processAccessibilityReport ( ) ;
17
+ const updateSubj = ( args , stateType , newSubject ) =>
18
+ stateType === 'parent' ? args : [ newSubject , ...args . slice ( 1 ) ] ;
19
+
20
+ const runCustomizedChainingCommand = ( ) => {
21
+ if ( ! Subject ) {
22
+ let cypressCommandSubject = null ;
23
+ const subjectFn = cy && cy . subject ;
24
+ if ( subjectFn !== null && subjectFn !== void 0 ) {
25
+ cypressCommandSubject = subjectFn . call ( cy ) ;
26
+ }
27
+ cycustomChaining
28
+ . then ( ( ) => cypressCommandSubject )
29
+ . then ( ( ) => {
30
+ originalFn ( ...args ) ;
31
+ } ) ;
32
+ } else {
33
+ let cypressCommandChain = null , setTimeout = null ;
34
+ // Extract timeout value if present
35
+ const timeoutArg = args . find ( arg => arg !== null && arg !== void 0 ? arg . timeout : null ) ;
36
+ if ( timeoutArg !== null && timeoutArg !== void 0 ) {
37
+ setTimeout = timeoutArg . timeout ;
38
+ }
39
+ const subjectChainFn = cy && cy . subjectChain ;
40
+ if ( subjectChainFn !== null && subjectChainFn !== void 0 ) {
41
+ cypressCommandChain = subjectChainFn . call ( cy ) ;
42
+ }
43
+ cycustomChaining . performScanSubjectQuery ( cypressCommandChain , setTimeout ) . then ( { timeout : 30000 } , ( newSubject ) => originalFn ( ...updateSubj ( args , stateType , newSubject ) ) ) ;
44
+ }
45
+ }
46
+ runCustomizedChainingCommand ( ) ;
47
+ }
48
+
49
+ Cypress . Commands . add ( 'processAccessibilityReport' , ( ) => {
50
+ try {
51
+ cy . window ( ) . then ( ( win ) => {
52
+ return cy . wrap ( processAccessibilityReport ( win ) , { timeout : 45000 } ) ;
53
+ } ) ;
54
+ } catch ( error ) {
55
+ console . log ( `Error in performing scan with error: ${ error . message } ` ) ;
56
+ }
57
+ } )
15
58
16
59
const setScanConfig = ( win , payload ) => {
17
60
return new Promise ( ( resolve , reject ) => {
@@ -76,7 +119,7 @@ const sendScanData = (win, payload) => {
76
119
} ) ;
77
120
} ;
78
121
79
- async function processAccessibilityReport ( url , windowNew ) {
122
+ const processAccessibilityReport = async ( windowNew ) => {
80
123
try {
81
124
let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
82
125
let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) === "true" ;
@@ -89,7 +132,7 @@ async function processAccessibilityReport(url,windowNew) {
89
132
needsReview : needsReviewValue
90
133
} ;
91
134
92
- console . log ( 'log' , "SET SCAN: Payload to send: for url: " , payloadToSend , url ) ;
135
+ console . log ( 'log' , "SET SCAN: Payload to send: " , payloadToSend ) ;
93
136
try {
94
137
let setResult = await setScanConfig ( windowNew , payloadToSend ) ;
95
138
console . log ( 'SET SCAN: response:' , setResult ) ;
@@ -211,22 +254,18 @@ const overRideCommands = JSON.parse(Cypress.env("ACCESSIBILITY_OVERIDE_COMMANDS"
211
254
212
255
if ( overRideCommands ) {
213
256
commandsToOverride . forEach ( ( command ) => {
214
- Cypress . Commands . overwrite ( command , ( originalFn , url , options ) => {
257
+ Cypress . Commands . overwrite ( command , ( originalFn , ... args ) => {
215
258
let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
216
- if ( ! isAccessibilityLoaded ) {
217
- console . log ( 'log' , "Accessibility not enabled." ) ;
218
- return originalFn ( url , options ) ;
259
+ const state = cy . state ( 'current' ) , Subject = 'getSubjectFromChain' in cy ;
260
+ const stateName = state === null || state === void 0 ? void 0 : state . get ( 'name' ) ;
261
+ let stateType = null ;
262
+ if ( ! isAccessibilityLoaded || ( stateName && stateName !== command ) ) {
263
+ return originalFn ( ...args ) ;
219
264
}
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
- } ) ;
265
+ if ( state !== null && state !== void 0 ) {
266
+ stateType = state . get ( 'type' ) ;
267
+ }
268
+ performNewLambdaScan ( originalFn , Subject , stateType , ...args ) ;
230
269
231
270
} ) ;
232
271
} ) ;
@@ -251,22 +290,34 @@ if (overRideCommands) {
251
290
oldprocessAccessibilityReport ( win ) ;
252
291
} )
253
292
} )
293
+ }
294
+ afterEach ( ( ) => {
295
+ if ( overRideCommands ) {
296
+ cy . window ( ) . then ( async ( win ) => {
297
+ let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
298
+ if ( ! isAccessibilityLoaded ) return cy . wrap ( { } ) ;
254
299
255
- afterEach ( ( ) => {
300
+ cy . wrap ( processAccessibilityReport ( win ) , { timeout : 30000 } )
301
+ } ) ;
302
+ } else {
256
303
console . log ( "after each hook" )
257
304
let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
258
305
if ( ! isAccessibilityLoaded ) {
259
306
console . log ( 'log' , "accessibility not enabled " + isAccessibilityLoaded ) ;
260
307
return ;
261
308
}
262
309
cy . window ( ) . then ( ( win ) => {
263
- processAccessibilityReport ( win ) ;
310
+ oldprocessAccessibilityReport ( win ) ;
264
311
} )
312
+ }
265
313
314
+ } )
266
315
267
- } )
316
+ if ( ! Cypress . Commands . hasOwnProperty ( '_lambdaTestSDKQueryAdded' ) ) {
317
+ Cypress . Commands . addQuery ( 'performScanSubjectQuery' , function ( chaining , setTimeout ) {
318
+ this . set ( 'timeout' , setTimeout ) ;
319
+ return ( ) => cy . getSubjectFromChain ( chaining ) ;
320
+ } ) ;
321
+ Cypress . Commands . _lambdaTestSDKQueryAdded = true ;
268
322
}
269
323
270
-
271
-
272
-
0 commit comments