From 34cdd9d93ce5298fdae9d6d45b9ee41d406db7d0 Mon Sep 17 00:00:00 2001 From: asirvadAbrahamVarghese Date: Mon, 13 Oct 2025 13:52:11 +0530 Subject: [PATCH 1/2] Added selectTableRowsByText command --- .../commands/miq_data_table_commands.js | 55 +++++++++++++++++++ cypress/support/e2e.js | 1 + 2 files changed, 56 insertions(+) create mode 100644 cypress/support/commands/miq_data_table_commands.js diff --git a/cypress/support/commands/miq_data_table_commands.js b/cypress/support/commands/miq_data_table_commands.js new file mode 100644 index 00000000000..3cbe466c1a8 --- /dev/null +++ b/cypress/support/commands/miq_data_table_commands.js @@ -0,0 +1,55 @@ +/* eslint-disable no-undef */ + +/** + * @fileoverview + * This file contains Cypress commands for interacting with data tables in the ManageIQ UI. + */ + +/** + * Command to select table rows that contain any of the specified text values. + * This command iterates through each text in the array and finds the corresponding row. + * If any text is not found in the table, it throws an error immediately. + * + * @param {Object} params - Parameters for the command + * @param {Array} params.textArray - Array of text values to match against table rows + */ +Cypress.Commands.add('selectTableRowsByText', ({ textArray = [] }) => { + if (!textArray || !textArray.length) { + cy.logAndThrowError('textArray is required'); + } + + cy.get('.miq-data-table table tbody tr').then(($rows) => { + const rows = Array.from($rows); + textArray.forEach((textToFind, textItemIndex) => { + const textFoundInTable = rows.some((row, rowIndex) => { + const $row = Cypress.$(row); + + // Skip already selected rows + if ($row.hasClass('bx--data-table--selected')) { + return false; + } + + const cells = Array.from($row.find('td')); + const textFoundInRow = cells.some( + (cell) => cell.innerText.trim() === textToFind // if true will break the cell loop, if false will continue to next cell + ); + + // If text is found in this row, select it & break the row loop + if (textFoundInRow) { + cy.log(`Found text "${textToFind}" (index: ${textItemIndex}) in row ${rowIndex + 1}`); + cy.wrap($row).find('.bx--checkbox-label').click(); + return true; + } + + return false; // Continue to next row + }); + + // After checking all rows, if the text wasn't found, throw an error and terminate + if (!textFoundInTable) { + cy.logAndThrowError( + `Text "${textToFind}" (index: ${textItemIndex}) was not found in the table` + ); + } + }); + }); +}); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 09177936fcb..31cb092585f 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -48,6 +48,7 @@ import './commands/form_elements_validation_commands.js'; import './commands/gtl.js'; import './commands/login.js'; import './commands/menu.js'; +import './commands/miq_data_table_commands.js'; import './commands/select.js'; import './commands/stub_notifications.js'; import './commands/tabs.js'; From f7733dd3287a85635b52a6d7feb80b73d64336c9 Mon Sep 17 00:00:00 2001 From: asirvadAbrahamVarghese Date: Mon, 13 Oct 2025 13:52:45 +0530 Subject: [PATCH 2/2] Updated cypress README with selectTableRowsByText command info --- cypress/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cypress/README.md b/cypress/README.md index d23a9bda0b0..cc4f09ccac2 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -52,6 +52,10 @@ ManageIQ implements the following cypress extensions: * `cy.menu('primaryMenu', 'secondaryMenu', 'tertiaryMenu')` - navigates the side bar menu items. `primaryMenu`: String for the outer menu item on the side bar. `secondaryMenu`: String for the secondary menu when a side bar menu item is clicked. `tertiaryMenu`: String (optional) for the tertiary menu when a side bar secondary item is clicked. (e.g. `cy.menu('Overview', 'Dashboard')` will navigate to the Overview > Dashboard page while `cy.menu('Overview', 'Chargeback', 'Rates')` will navigate to the Overview > Chargeback > Rates page). * `cy.menuItems()` - returns an Array of `{ title: String, items: Array of { title: String, href: String, items: Array of { title: String, href: String } }}` for the menu items on the side bar. `title`: String for the menu item title. `href`: String for the url to navigate to, included when the menu item has no children. `items`: Array of the same object with `title` and `href`/`items`, this is included when the menu item has children menu items. +##### miq_data_table_commands + +* `cy.selectTableRowsByText({ textArray })` - selects table rows that contain any of the specified text values. Iterates through each text in the array and finds the corresponding row. If any text is not found in the table, it throws an error immediately. `textArray` is an array of text values to match against table rows. e.g. `cy.selectTableRowsByText({ textArray: ['Option 1', 'Option 2'] });` + ##### tabs * `cy.tabs({ tabLabel })` - finds a tab element within a tablist that contains the specified label text and automatically clicks it to navigate to the tab. It requires a `tabLabel` parameter and will throw an error if none is provided. `tabLabel` is the text content of the tab to select. Returns a Cypress chainable element representing the selected tab. e.g. `cy.tabs({ tabLabel: 'Collect Logs' });`, `cy.tabs({ tabLabel: 'Settings' }).then(() => { cy.get('input#name').should('be.visible'); });`