@@ -33,38 +33,33 @@ function expandAllFolders (browser: NightwatchBrowser, targetDirectory?: string,
33
33
} )
34
34
} )
35
35
. perform ( ( ) => {
36
- let iteration = 0
37
- const maxIterations = 20 // Prevent infinite loops
36
+ let attempts = 0
37
+ const maxAttempts = 200
38
38
39
- const clickNext = ( ) => {
40
- if ( iteration >= maxIterations ) {
39
+ const expandNextClosedFolder = ( ) => {
40
+ if ( attempts >= maxAttempts ) {
41
41
if ( done ) done ( )
42
42
return
43
43
}
44
+ attempts ++
44
45
45
- iteration ++
46
+ const closedFolderSelector = targetDirectory
47
+ ? `li[data-id*="treeViewLitreeViewItem${ targetDirectory } "] .fa-folder:not(.fa-folder-open)`
48
+ : 'li[data-id*="treeViewLitreeViewItem"] .fa-folder:not(.fa-folder-open)'
46
49
47
- // Find folders that are not expanded, / in case no folder is passed
48
- const folderSelector = targetDirectory ?
49
- `li[data-id*="treeViewLitreeViewItem${ targetDirectory } "] li[data-id*="treeViewLitreeViewItem"] .fa-folder:not(.fa-folder-open)` :
50
- 'li[data-id*="treeViewLitreeViewItem"] .fa-folder:not(.fa-folder-open)'
51
-
52
- browser . element ( 'css selector' , folderSelector , ( result ) => {
50
+ browser . element ( 'css selector' , closedFolderSelector , ( result ) => {
53
51
if ( result . status === 0 && result . value ) {
54
- // Found a closed folder, click its parent li element
55
- browser . element ( 'css selector' , folderSelector , ( elementResult ) => {
56
- if ( elementResult . status === 0 ) {
57
- browser . elementIdElement ( ( elementResult . value as any ) [ 'element-6066-11e4-a52e-4f735466cecf' ] , 'xpath' , './..' , ( parentResult ) => {
58
- if ( parentResult . status === 0 ) {
59
- browser . elementIdClick ( ( parentResult . value as any ) [ 'element-6066-11e4-a52e-4f735466cecf' ] ) // click on folder name
60
- . pause ( 100 )
61
- . perform ( ( ) => clickNext ( ) ) // recursive nested folders
62
- } else {
63
- if ( done ) done ( )
64
- }
65
- } )
52
+ // Found a closed folder icon, now find its parent li element and click it
53
+ browser . elementIdElement ( ( result . value as any ) [ 'element-6066-11e4-a52e-4f735466cecf' ] , 'xpath' , './..' , ( parentResult ) => {
54
+ if ( parentResult . status === 0 ) {
55
+ browser . elementIdClick ( ( parentResult . value as any ) [ 'element-6066-11e4-a52e-4f735466cecf' ] )
56
+ . pause ( 100 ) // Wait for folder to expand and DOM to update
57
+ . perform ( ( ) => expandNextClosedFolder ( ) ) // Look for next closed folder
66
58
} else {
67
- if ( done ) done ( )
59
+ // Failed to find parent, try alternative approach
60
+ browser . click ( closedFolderSelector )
61
+ . pause ( 100 )
62
+ . perform ( ( ) => expandNextClosedFolder ( ) ) // recursive call
68
63
}
69
64
} )
70
65
} else {
@@ -73,7 +68,7 @@ function expandAllFolders (browser: NightwatchBrowser, targetDirectory?: string,
73
68
} )
74
69
}
75
70
76
- clickNext ( )
71
+ expandNextClosedFolder ( )
77
72
} )
78
73
}
79
74
0 commit comments