Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'); });`
Expand Down
55 changes: 55 additions & 0 deletions cypress/support/commands/miq_data_table_commands.js
Original file line number Diff line number Diff line change
@@ -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<string>} 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`
);
}
});
});
});
1 change: 1 addition & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down