Skip to content

Commit 934868b

Browse files
Add table row click command based on text and optional column
1 parent 03e55ca commit 934868b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cypress/support/commands/miq_data_table_commands.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,23 @@ Cypress.Commands.add('selectTableRowsByText', ({ textArray = [] }) => {
5353
});
5454
});
5555
});
56+
57+
/**
58+
* Command to click on a table row that contains the specified text.
59+
* If columnIndex is provided, it will only look for the text in that specific column.
60+
*
61+
* @param {Object} params - Parameters for the command
62+
* @param {string} params.text - Text to find in the table row
63+
* @param {number} [params.columnIndex] - Optional index of the column to search in (0-based)
64+
*/
65+
Cypress.Commands.add('clickTableRowByText', ({ text, columnIndex }) => {
66+
if (!text) {
67+
cy.logAndThrowError('text parameter is required');
68+
}
69+
70+
if (columnIndex || columnIndex === 0) {
71+
cy.contains(`.miq-data-table table tbody tr td:nth-child(${columnIndex + 1})`, text).click();
72+
} else {
73+
cy.contains('.miq-data-table table tbody tr td', text).click();
74+
}
75+
});

0 commit comments

Comments
 (0)