@@ -33,9 +33,9 @@ Cypress.Commands.add('accordionItem', (name) => {
33
33
* If the path is not found, it will throw an error.
34
34
*/
35
35
Cypress . 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' ) ] ;
39
39
40
40
/**
41
41
* Function to recursively expand the accordion and click the target item.
@@ -105,16 +105,16 @@ Cypress.Commands.add('selectAccordionItem', (accordionPath) => {
105
105
return ;
106
106
}
107
107
}
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 ( ) ;
109
114
const errorMessage = `${
110
115
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 ) ;
118
118
} ;
119
119
120
120
// Start the recursive call from the first label in the given path
0 commit comments