@@ -210,8 +210,32 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
210210 cy . logAndThrowError ( errorMessage ) ;
211211 } ;
212212
213- // Start the recursive call from the first label in the given path
213+ // If no list items are found initially - wait for them to load and
214+ // then start the recursive call from the first label in the given path
214215 // and from the beginning of the accordion items in the panel
215- expandAndClickPath ( 0 , 0 ) ;
216+ if ( listItems . length ) {
217+ expandAndClickPath ( 0 , 0 ) ;
218+ } else {
219+ Cypress . log ( {
220+ name : '⚠️ selectAccordionItem' ,
221+ message : 'No list items found initially - waiting for them to load' ,
222+ } ) ;
223+
224+ cy . get ( 'div.panel-collapse.collapse.in' ) . then ( ( freshAccordion ) => {
225+ cy . wrap ( freshAccordion )
226+ . find ( 'li.list-group-item' )
227+ . should ( 'have.length.greaterThan' , 0 )
228+ . then ( ( loadedListItems ) => {
229+ // Update references with the loaded data
230+ expandedAccordion = freshAccordion ;
231+ listItems = [ ...loadedListItems ] ;
232+ Cypress . log ( {
233+ name : '🟢 selectAccordionItem' ,
234+ message : `List items loaded - found ${ listItems . length } items` ,
235+ } ) ;
236+ expandAndClickPath ( 0 , 0 ) ;
237+ } ) ;
238+ } ) ;
239+ }
216240 } ) ;
217241} ) ;
0 commit comments