@@ -33,9 +33,9 @@ Cypress.Commands.add('accordionItem', (name) => {
3333 * If the path is not found, it will throw an error.
3434 */
3535Cypress . Commands . add ( 'selectAccordionItem' , ( accordionPath ) => {
36- cy . get ( 'div.panel-collapse.collapse.in li.list-group-item ' ) . then ( ( $items ) => {
37- // Converting jQuery collection to an array for easier manipulation
38- const listItems = [ ...$items ] ;
36+ cy . get ( 'div.panel-collapse.collapse.in' ) . then ( ( expandedAccordion ) => {
37+ // Converting the list-items jQuery collection to an array for easier manipulation
38+ const listItems = [ ...expandedAccordion . find ( 'li.list-group-item' ) ] ;
3939
4040 /**
4141 * Function to recursively expand the accordion and click the target item.
@@ -105,16 +105,16 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
105105 return ;
106106 }
107107 }
108- // If we reach here, it means the label was not found
108+ // Reaching this point indicates the label was not found - throw an error and exit.
109+ // Traversing up through the ancestors to get the name of the accordion where the lookup was performed
110+ const accordionPanel = expandedAccordion
111+ . closest ( '.panel' )
112+ . find ( '.panel-heading h4.panel-title a' )
113+ . text ( ) ;
109114 const errorMessage = `${
110115 isClickableNode ? 'Target' : 'Intermediate'
111- } node - "${ accordionLabel } " was not found`;
112- Cypress . log ( {
113- name : 'error' ,
114- displayName : '❗ CypressError:' ,
115- message : errorMessage ,
116- } ) ;
117- throw new Error ( errorMessage ) ;
116+ } node - "${ accordionLabel } " was not found in the expanded "${ accordionPanel } " accordion panel.`;
117+ cy . logAndThrowError ( errorMessage ) ;
118118 } ;
119119
120120 // Start the recursive call from the first label in the given path
0 commit comments