@@ -7,17 +7,44 @@ const browserStackLog = (message) => {
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
9
const commandToOverwrite = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
10
- commandToOverwrite . forEach ( ( command ) => {
11
- Cypress . Commands . overwrite ( command , ( originalFn , url , options ) => {
12
- const attributes = Cypress . mocha . getRunner ( ) . suite . ctx . currentTest || Cypress . mocha . getRunner ( ) . suite . ctx . _runnable ;
13
- let shouldScanTestForAccessibility = shouldScanForAccessibility ( attributes ) ;
14
- if ( ! shouldScanTestForAccessibility ) {
15
- cy . wrap ( null ) . then ( ( ) => originalFn ( url , options ) ) ;
16
- return ;
17
- }
18
- else cy . wrap ( null ) . performScan ( ) . then ( ( ) => originalFn ( url , options ) ) ;
19
- } ) ;
20
- } ) ;
10
+ const performModifiedScan = ( originalFn , Subject , stateType , ...args ) => {
11
+ let customChaining = cy . wrap ( null ) . performScan ( ) ;
12
+ function changeSub ( args , stateType , newSubject ) {
13
+ if ( stateType !== 'parent' ) {
14
+ return [ newSubject , ...args . slice ( 1 ) ] ;
15
+ }
16
+ return args ;
17
+ }
18
+ function runCutomizedCommand ( ) {
19
+ 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 ) ) ) ;
44
+ }
45
+ }
46
+ runCutomizedCommand ( ) ;
47
+ }
21
48
22
49
const performScan = ( win , payloadToSend ) =>
23
50
new Promise ( async ( resolve , reject ) => {
@@ -295,6 +322,26 @@ const shouldScanForAccessibility = (attributes) => {
295
322
return shouldScanTestForAccessibility ;
296
323
}
297
324
325
+ commandToOverwrite . forEach ( ( command ) => {
326
+ Cypress . Commands . overwrite ( command , ( originalFn , ...args ) => {
327
+ const attributes = Cypress . mocha . getRunner ( ) . suite . ctx . currentTest || Cypress . mocha . getRunner ( ) . suite . ctx . _runnable ;
328
+ const shouldScanTestForAccessibility = shouldScanForAccessibility ( attributes ) ;
329
+ const state = cy . state ( 'current' ) , Subject = 'getSubjectFromChain' in cy ;
330
+ const stateName = state === null || state === void 0 ? void 0 : state . get ( 'name' ) ;
331
+ let stateType ;
332
+ if ( ! shouldScanTestForAccessibility || ( stateName && stateName !== command ) ) {
333
+ return originalFn ( ...args ) ;
334
+ }
335
+ if ( state !== null && state !== void 0 ) {
336
+ stateType = state . get ( 'type' ) ;
337
+ }
338
+ else {
339
+ stateType = null ;
340
+ }
341
+ performModifiedScan ( originalFn , Subject , stateType , ...args ) ;
342
+ } ) ;
343
+ } ) ;
344
+
298
345
afterEach ( ( ) => {
299
346
const attributes = Cypress . mocha . getRunner ( ) . suite . ctx . currentTest ;
300
347
cy . window ( ) . then ( async ( win ) => {
@@ -400,3 +447,8 @@ Cypress.Commands.add('getAccessibilityResults', () => {
400
447
browserStackLog ( `Error in getting accessibilty results with error: ${ error . message } ` ) ;
401
448
}
402
449
} ) ;
450
+
451
+ Cypress . Commands . addQuery ( 'performScanSubjectQuery' , function ( chaining , setTimeout ) {
452
+ this . set ( 'timeout' , setTimeout ) ;
453
+ return ( ) => cy . getSubjectFromChain ( chaining ) ;
454
+ } ) ;
0 commit comments