Skip to content

Commit 696d6cd

Browse files
authored
Merge pull request #9655 from asirvadAbrahamVarghese/add-miq-data-table-commands
Add miq data table commands
2 parents 03c3260 + f7733dd commit 696d6cd

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

cypress/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ ManageIQ implements the following cypress extensions:
5252
* `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).
5353
* `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.
5454

55+
##### miq_data_table_commands
56+
57+
* `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'] });`
58+
5559
##### tabs
5660

5761
* `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'); });`
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* eslint-disable no-undef */
2+
3+
/**
4+
* @fileoverview
5+
* This file contains Cypress commands for interacting with data tables in the ManageIQ UI.
6+
*/
7+
8+
/**
9+
* Command to select table rows that contain any of the specified text values.
10+
* This command iterates through each text in the array and finds the corresponding row.
11+
* If any text is not found in the table, it throws an error immediately.
12+
*
13+
* @param {Object} params - Parameters for the command
14+
* @param {Array<string>} params.textArray - Array of text values to match against table rows
15+
*/
16+
Cypress.Commands.add('selectTableRowsByText', ({ textArray = [] }) => {
17+
if (!textArray || !textArray.length) {
18+
cy.logAndThrowError('textArray is required');
19+
}
20+
21+
cy.get('.miq-data-table table tbody tr').then(($rows) => {
22+
const rows = Array.from($rows);
23+
textArray.forEach((textToFind, textItemIndex) => {
24+
const textFoundInTable = rows.some((row, rowIndex) => {
25+
const $row = Cypress.$(row);
26+
27+
// Skip already selected rows
28+
if ($row.hasClass('bx--data-table--selected')) {
29+
return false;
30+
}
31+
32+
const cells = Array.from($row.find('td'));
33+
const textFoundInRow = cells.some(
34+
(cell) => cell.innerText.trim() === textToFind // if true will break the cell loop, if false will continue to next cell
35+
);
36+
37+
// If text is found in this row, select it & break the row loop
38+
if (textFoundInRow) {
39+
cy.log(`Found text "${textToFind}" (index: ${textItemIndex}) in row ${rowIndex + 1}`);
40+
cy.wrap($row).find('.bx--checkbox-label').click();
41+
return true;
42+
}
43+
44+
return false; // Continue to next row
45+
});
46+
47+
// After checking all rows, if the text wasn't found, throw an error and terminate
48+
if (!textFoundInTable) {
49+
cy.logAndThrowError(
50+
`Text "${textToFind}" (index: ${textItemIndex}) was not found in the table`
51+
);
52+
}
53+
});
54+
});
55+
});

cypress/support/e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import './commands/form_elements_validation_commands.js';
4848
import './commands/gtl.js';
4949
import './commands/login.js';
5050
import './commands/menu.js';
51+
import './commands/miq_data_table_commands.js';
5152
import './commands/select.js';
5253
import './commands/stub_notifications.js';
5354
import './commands/tabs.js';

0 commit comments

Comments
 (0)