From 94df1b49151f261ea953359a14ec2a1325a4c046 Mon Sep 17 00:00:00 2001 From: asirvadAbrahamVarghese Date: Mon, 13 Oct 2025 16:48:53 +0530 Subject: [PATCH 1/2] Added command to target form legend elements --- cypress/support/commands/element_selectors.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cypress/support/commands/element_selectors.js b/cypress/support/commands/element_selectors.js index 5f83961c740..9db791858b5 100644 --- a/cypress/support/commands/element_selectors.js +++ b/cypress/support/commands/element_selectors.js @@ -67,6 +67,25 @@ Cypress.Commands.add('getFormLabelByForAttribute', ({ forValue }) => { return cy.get(`#main-content .bx--form label[for="${forValue}"]`); }); +/** + * Retrieves a form legend element by its text content. + * + * @param {Object} options - The options object. + * @param {string} options.legendText - The text content of the legend element (required). + * @returns {Element} The matched legend element. + * @throws {Error} If legendText is not provided. + * + * Example: + * cy.getFormLegendByText({ legendText: 'Personal Information' }); + * cy.getFormLegendByText({ legendText: 'Payment Details' }); + */ +Cypress.Commands.add('getFormLegendByText', ({ legendText }) => { + if (!legendText) { + cy.logAndThrowError('legendText is required'); + } + return cy.contains('#main-content form legend.bx--label', legendText); +}); + /** * Retrieves a form select field by its ID using an object parameter. * From d0093171a89f55ac012f73412bd46bf521648a46 Mon Sep 17 00:00:00 2001 From: asirvadAbrahamVarghese Date: Mon, 13 Oct 2025 16:49:54 +0530 Subject: [PATCH 2/2] Updated cypress README with getFormLegendByText command info --- cypress/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cypress/README.md b/cypress/README.md index 03c6f982968..dba5ee2210d 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -85,6 +85,7 @@ ManageIQ implements the following cypress extensions: * `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'});` * `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'});` * `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'});` +* `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'});` * `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'});` * `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'});`