diff --git a/cypress/README.md b/cypress/README.md index 8bfc738bd85..6fcaf29ef16 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -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). @@ -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 @@ -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. diff --git a/cypress/support/assertions/miq_data_table_assertions.js b/cypress/support/assertions/miq_data_table_assertions.js new file mode 100644 index 00000000000..5161c5a48eb --- /dev/null +++ b/cypress/support/assertions/miq_data_table_assertions.js @@ -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'); + } +); diff --git a/cypress/support/commands/gtl.js b/cypress/support/commands/gtl.js index fdacf92e295..65de35850ea 100644 --- a/cypress/support/commands/gtl.js +++ b/cypress/support/commands/gtl.js @@ -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'); }); diff --git a/cypress/support/commands/miq_data_table_commands.js b/cypress/support/commands/miq_data_table_commands.js index 3cbe466c1a8..3923bfec50f 100644 --- a/cypress/support/commands/miq_data_table_commands.js +++ b/cypress/support/commands/miq_data_table_commands.js @@ -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(); + } +}); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 4a1915269d6..c5051a30084 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -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: // ***********************************************************