@@ -12,6 +12,49 @@ const commandsToOverride = [
1212
1313const commandsToWrap = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scroll' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
1414
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+ } )
1558
1659const setScanConfig = ( win , payload ) => {
1760 return new Promise ( ( resolve , reject ) => {
@@ -76,7 +119,7 @@ const sendScanData = (win, payload) => {
76119 } ) ;
77120} ;
78121
79- async function processAccessibilityReport ( url , windowNew ) {
122+ const processAccessibilityReport = async ( windowNew ) => {
80123 try {
81124 let wcagCriteriaValue = Cypress . env ( "WCAG_CRITERIA" ) || "wcag21a" ;
82125 let bestPracticeValue = Cypress . env ( "BEST_PRACTICE" ) === "true" ;
@@ -89,7 +132,7 @@ async function processAccessibilityReport(url,windowNew) {
89132 needsReview : needsReviewValue
90133 } ;
91134
92- console . log ( 'log' , "SET SCAN: Payload to send: for url: " , payloadToSend , url ) ;
135+ console . log ( 'log' , "SET SCAN: Payload to send: " , payloadToSend ) ;
93136 try {
94137 let setResult = await setScanConfig ( windowNew , payloadToSend ) ;
95138 console . log ( 'SET SCAN: response:' , setResult ) ;
@@ -211,22 +254,18 @@ const overRideCommands = JSON.parse(Cypress.env("ACCESSIBILITY_OVERIDE_COMMANDS"
211254
212255if ( overRideCommands ) {
213256 commandsToOverride . forEach ( ( command ) => {
214- Cypress . Commands . overwrite ( command , ( originalFn , url , options ) => {
257+ Cypress . Commands . overwrite ( command , ( originalFn , ... args ) => {
215258 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 ) ;
219264 }
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 ) ;
230269
231270 } ) ;
232271 } ) ;
@@ -251,22 +290,34 @@ if (overRideCommands) {
251290 oldprocessAccessibilityReport ( win ) ;
252291 } )
253292 } )
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 ( { } ) ;
254299
255- afterEach ( ( ) => {
300+ cy . wrap ( processAccessibilityReport ( win ) , { timeout : 30000 } )
301+ } ) ;
302+ } else {
256303 console . log ( "after each hook" )
257304 let isAccessibilityLoaded = Cypress . env ( "ACCESSIBILITY" ) || false ;
258305 if ( ! isAccessibilityLoaded ) {
259306 console . log ( 'log' , "accessibility not enabled " + isAccessibilityLoaded ) ;
260307 return ;
261308 }
262309 cy . window ( ) . then ( ( win ) => {
263- processAccessibilityReport ( win ) ;
310+ oldprocessAccessibilityReport ( win ) ;
264311 } )
312+ }
265313
314+ } )
266315
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 ;
268322}
269323
270-
271-
272-
0 commit comments