Skip to content

Commit 94df1b4

Browse files
Added command to target form legend elements
1 parent 611b461 commit 94df1b4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cypress/support/commands/element_selectors.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ Cypress.Commands.add('getFormLabelByForAttribute', ({ forValue }) => {
6767
return cy.get(`#main-content .bx--form label[for="${forValue}"]`);
6868
});
6969

70+
/**
71+
* Retrieves a form legend element by its text content.
72+
*
73+
* @param {Object} options - The options object.
74+
* @param {string} options.legendText - The text content of the legend element (required).
75+
* @returns {Element} The matched legend element.
76+
* @throws {Error} If legendText is not provided.
77+
*
78+
* Example:
79+
* cy.getFormLegendByText({ legendText: 'Personal Information' });
80+
* cy.getFormLegendByText({ legendText: 'Payment Details' });
81+
*/
82+
Cypress.Commands.add('getFormLegendByText', ({ legendText }) => {
83+
if (!legendText) {
84+
cy.logAndThrowError('legendText is required');
85+
}
86+
return cy.contains('#main-content form legend.bx--label', legendText);
87+
});
88+
7089
/**
7190
* Retrieves a form select field by its ID using an object parameter.
7291
*

0 commit comments

Comments
 (0)