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
7 changes: 7 additions & 0 deletions cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ ManageIQ implements the following cypress extensions:

* `cy.logAndThrowError(messageToLog, messageToThrow)` - Logs a custom error message to Cypress log and then throws an error. `messageToLog` is the message to display in the Cypress command log. `messageToThrow` is the optional error message to throw, defaults to `messageToLog`. e.g. `cy.logAndThrowError('This is the logged message', 'This is the thrown error message');`, `cy.logAndThrowError('This is the message that gets logged and thrown');`

##### element_selectors

* `cy.getFormFooterButtonByType(name, type)` - retrieves form footer button by its name and type. `name` is the name or text content of the button. `type` is the HTML button type (e.g., 'button', 'submit', 'reset'). Defaults to 'button'. e.g. `cy.getFormFooterButtonByType('Save');`, `cy.getFormFooterButtonByType('Reset', 'reset');`
* `cy.getFormInputFieldById(inputId, type)` - retrieves a form input field by its ID and type. `inputId` is the ID of the input field. `type` is the HTML input type (e.g., 'text', 'email', 'password'). Defaults to 'text'. e.g. `cy.getFormInputFieldById('name');`, `cy.getFormInputFieldById('name', 'text');`
* `getFormLabelByInputId(inputId)` - retrieves a form label associated with a specific input field by its ID. `inputId` is the ID of the input field. e.g. `cy.getFormLabelByInputId('name');`
* `cy.getFormSelectFieldById(selectId)` - retrieves a form select field by its ID. `selectId` is the ID of the select field. e.g. `cy.getFormSelectFieldById('select-scan-limit');`

#### Assertions

* `cy.expect_explorer_title(title)` - check that the title on an explorer screen matches the provided title. `title`: String for the title.
Expand Down
57 changes: 57 additions & 0 deletions cypress/support/commands/element_selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable no-undef */

/**
* Retrieves a form footer button by its name and type.
*
* @param {string} name - The name or text content of the button.
* @param {string} [type='button'] - The HTML button type (e.g., 'button', 'submit', 'reset'). Defaults to 'button'.
* @returns {Element} The matched button element.
*
* Example:
* cy.getFormFooterButtonByType('Save Changes');
* cy.getFormFooterButtonByType('Reset', 'reset');
*/
Cypress.Commands.add('getFormFooterButtonByType', (name, type = 'button') =>
cy.contains(`#main-content .bx--btn-set button[type="${type}"]`, name)
);

/**
* Retrieves a form input field by its ID and type.
*
* @param {string} inputId - The ID of the input field.
* @param {string} [type='text'] - The HTML input type (e.g., 'text', 'email', 'password'). Defaults to 'text'.
* @returns {Element} The matched input field element.
*
* Example:
* cy.getFormInputFieldById('name');
* cy.getFormInputFieldById('name', 'text');
*/
Cypress.Commands.add('getFormInputFieldById', (inputId, type = 'text') =>
cy.get(`#main-content .bx--form input#${inputId}[type="${type}"]`)
);

/**
* Retrieves a form label associated with a specific input field by its ID.
*
* @param {string} inputId - The ID of the input field.
* @returns {Element} The matched label element.
*
* Example:
* cy.getFormLabelByInputId('name');
*/
Cypress.Commands.add('getFormLabelByInputId', (inputId) =>
cy.get(`#main-content .bx--form label[for="${inputId}"]`)
);

/**
* Retrieves a form select field by its ID.
*
* @param {string} selectId - The ID of the select field.
* @returns {Element} The matched select field element.
*
* Example:
* cy.getFormSelectFieldById('select-scan-limit');
*/
Cypress.Commands.add('getFormSelectFieldById', (selectId) =>
cy.get(`#main-content .bx--form select#${selectId}`)
);
1 change: 1 addition & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

// Commands
import './commands/custom_logging_commands.js';
import './commands/element_selectors.js';
import './commands/explorer.js';
import './commands/gtl.js';
import './commands/login.js';
Expand Down