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
3 changes: 2 additions & 1 deletion cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ManageIQ implements the following cypress extensions:
##### gtl

* `cy.gtl_error()` - check that error message is present.
* `cy.gtl_no_record()` - check that `No Record` message is present.
* `cy.gtlGetTable()` - returns GTL table.
* `cy.gtlGetRows(columns)` - return GTL table row data in an array. `columns`: Array of 0-based indexes of the columns to read (e.g. [1, 2, 3] will return all row data from columns 1, 2, and 3).
* `cy.gtlClickRow(columns)` - click on a row in a GTL table. `columns`: Array of `{ title: String, number: Integer }`. `title` is the string you want to find in the table to click on, `number` is the column that string is found in. (e.g. `[{title: 'Default', number: 1}, {title: 'Compute', number: 2}]` will click on a row in the GTL table with `Default` in column 1 and `Compute` in column 2. Using just `[{title: 'Default', number: 1}]` will click on the first row found in the GTL table with `Default` in column 1).
Expand All @@ -55,6 +54,7 @@ ManageIQ implements the following cypress extensions:
##### 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'] });`
* `cy.clickTableRowByText({ text, columnIndex })` - clicks on a table row that contains the specified text. If columnIndex is provided, it will only look for the text in that specific column. `text` is the text to find in the table row. `columnIndex` is an optional 0-based index of the column to search in. e.g. `cy.clickTableRowByText({ text: 'My Service' });`, `cy.clickTableRowByText({ text: 'Active', columnIndex: 2 });`

##### tabs

Expand Down Expand Up @@ -98,6 +98,7 @@ ManageIQ implements the following cypress extensions:
#### Assertions

* `cy.expect_explorer_title(title)` - check that the title on an explorer screen matches the provided title. `title`: String for the title.
* `cy.expect_gtl_no_records_with_text({ containsText })` - verifies that the GTL view displays a "no records" message. Checks that the specified text is visible within the GTL view container. `containsText` is the optional text to verify in the no records message (defaults to 'No records'). e.g. `cy.expect_gtl_no_records_with_text();`, `cy.expect_gtl_no_records_with_text({ containsText: 'No items found' });`
* `cy.expect_no_search_box()` - check if no searchbox is present on the screen.
* `cy.expect_rates_table(headers, rows)` - check the values in a chargeback rate table. `headers`: Array of strings representing the headers of the table. `rows`: Array of type `[String, [...String], [...String], [...String], [...String], String]` where each index of the array represents a column in the table. The arrays within the `rows` array can be any length and represent the values in each given column, e.g. an array of `[0.0, 100.0]` in the index for the `Range Start` column would verify that the column contains two range starts with values `0.0` and `100.0`.
* `cy.expect_show_list_title(title)` - check the title on a show\_list screen matches the provided title. `title`: String for the title.
Expand Down
23 changes: 23 additions & 0 deletions cypress/support/assertions/miq_data_table_assertions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable no-undef */

/**
* Command to verify that the GTL (Grid/Tile/List) view displays a "no records" message.
* This assertion checks that the specified text is visible within the GTL view container.
*
* @param {Object} params - Parameters for the command
* @param {string} [params.containsText='No records'] - The text to verify in the no records message
* @returns {Cypress.Chainable} A Cypress chainable that asserts the text is visible
* @example
* // Check for default "No records" message
* cy.expect_gtl_no_records_with_text();
*
* @example
* // Check for custom message
* cy.expect_gtl_no_records_with_text({ containsText: 'No items found' });
*/
Cypress.Commands.add(
'expect_gtl_no_records_with_text',
({ containsText = 'No records' } = {}) => {
return cy.contains('#miq-gtl-view', containsText).should('be.visible');
}
);
4 changes: 0 additions & 4 deletions cypress/support/commands/gtl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ Cypress.Commands.add('gtl_error', () => {
return cy.get('#miq-gtl-view > #flash_msg_div').should('be.visible');
});

Cypress.Commands.add('gtl_no_record', () => {
return cy.get('#miq-gtl-view > div.no-record').should('be.visible');
});

Cypress.Commands.add('gtlGetTable', () => {
return cy.get('#miq-gtl-view > .miq-data-table > .miq-data-table > .bx--data-table-content > table');
});
Expand Down
20 changes: 20 additions & 0 deletions cypress/support/commands/miq_data_table_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,23 @@ Cypress.Commands.add('selectTableRowsByText', ({ textArray = [] }) => {
});
});
});

/**
* Command to click on a table row that contains the specified text.
* If columnIndex is provided, it will only look for the text in that specific column.
*
* @param {Object} params - Parameters for the command
* @param {string} params.text - Text to find in the table row
* @param {number} [params.columnIndex] - Optional index of the column to search in (0-based)
*/
Cypress.Commands.add('clickTableRowByText', ({ text, columnIndex }) => {
if (!text) {
cy.logAndThrowError('text parameter is required');
}

if (columnIndex || columnIndex === 0) {
cy.contains(`.miq-data-table table tbody tr td:nth-child(${columnIndex + 1})`, text).click();
} else {
cy.contains('.miq-data-table table tbody tr td', text).click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 It's good to be case sensitive here and expect exact text since we'll be creating the objects with the right text so it should be easy to ensure we match it correctly.

It will be interesting to see if this miq-data-table structure holds for all pages containing the data table. I hope so but we'll see as we do more pages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had the same doubt, that’s why I’m keeping the selector minimal(without including classes) for now. Let’s see how it goes....

}
});
1 change: 1 addition & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import './assertions/expect_rates_table.js';
import './assertions/expect_search_box.js';
import './assertions/expect_text.js';
import './assertions/expect_title.js';
import './assertions/miq_data_table_assertions.js'

// cypress on rails setup:
// ***********************************************************
Expand Down