Skip to content

Commit 551e1f3

Browse files
authored
Merge pull request #9656 from asirvadAbrahamVarghese/add-form-element-selectors
Add form element selectors
2 parents 98af49a + d009317 commit 551e1f3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cypress/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ ManageIQ implements the following cypress extensions:
8585
* `cy.getFormFooterButtonByTypeWithText({ buttonType, buttonText })` - retrieves form footer button by its name and type. `buttonText` is the name or text content of the button. `buttonType` is the HTML button type (e.g., 'button', 'submit', 'reset'). Defaults to 'button'. e.g. `cy.getFormFooterButtonByType({buttonType: 'Reset', buttonText: 'reset'});`, `cy.getFormFooterButtonByTypeWithText({buttonText: 'Cancel'});`
8686
* `cy.getFormInputFieldByIdAndType({ inputId, inputType })` - retrieves a form input field by its ID and type. `inputId` is the ID of the input field. `inputType` is the HTML input type (e.g., 'text', 'email', 'password'). Defaults to 'text'. e.g. `cy.getFormInputFieldByIdAndType({inputId: 'name'});`, `cy.getFormInputFieldByIdAndType({inputId: 'name', inputType: 'text'});`
8787
* `cy.getFormLabelByForAttribute({ forValue })` - retrieves a form label associated with a specific input field by its 'for' attribute. `forValue` is the value of the 'for' attribute that matches the input field's ID. e.g. `cy.getFormLabelByForAttribute({forValue: 'name'});`
88+
* `cy.getFormLegendByText({ legendText })` - retrieves a form legend element by its text content. Legend elements are typically used as captions for fieldset elements in forms. `legendText` is the text content of the legend element. e.g. `cy.getFormLegendByText({legendText: 'Basic Information'});`
8889
* `cy.getFormSelectFieldById({ selectId })` - retrieves a form select field by its ID. `selectId` is the ID of the select field. e.g. `cy.getFormSelectFieldById({selectId: 'select-scan-limit'});`
8990
* `cy.getFormTextareaById({ textareaId })` - retrieves a form textarea field by its ID. `textareaId` is the ID of the textarea field. e.g. `cy.getFormTextareaById({textareaId: 'default.auth_key'});`
9091

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 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)