Skip to content

Commit b3a4299

Browse files
Add custom commands for selecting form elements
1 parent ef8fb4c commit b3a4299

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

cypress/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ ManageIQ implements the following cypress extensions:
5656
* `cy.toolbarItems(toolbarButton)` - returns an array of objects {text: String, disabled: Boolean} for the toolbar dropdown buttons for when a toolbar button is clicked. `toolbarButton` is the string for the text of the toolbar button that you want to click on.
5757
* `cy.toolbar(toolbarButton, dropdownButton)` - click on the toolbar button specified by the user. Can also then click on a specified dropdown button as well. `toolbarButton` is the string for the text of the toolbar button that you want to click on. `dropdownButton` is the string for the text of the toolbar dropdown button that you want to click on. s
5858

59+
##### element_selectors
60+
61+
* `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');`
62+
* `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');`
63+
* `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');`
64+
* `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');`
65+
5966
#### Assertions
6067

6168
* `cy.expect_explorer_title(title)` - check that the title on an explorer screen matches the provided title. `title`: String for the title.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-disable no-undef */
2+
3+
/**
4+
* Retrieves a form footer button by its name and type.
5+
*
6+
* @param {string} name - The name or text content of the button.
7+
* @param {string} [type='button'] - The HTML button type (e.g., 'button', 'submit', 'reset'). Defaults to 'button'.
8+
* @returns {Element} The matched button element.
9+
*
10+
* Example:
11+
* cy.getFormFooterButtonByType('Save Changes');
12+
* cy.getFormFooterButtonByType('Reset', 'reset');
13+
*/
14+
Cypress.Commands.add('getFormFooterButtonByType', (name, type = 'button') =>
15+
cy.contains(`#main-content .bx--btn-set button[type="${type}"]`, name)
16+
);
17+
18+
/**
19+
* Retrieves a form input field by its ID and type.
20+
*
21+
* @param {string} inputId - The ID of the input field.
22+
* @param {string} [type='text'] - The HTML input type (e.g., 'text', 'email', 'password'). Defaults to 'text'.
23+
* @returns {Element} The matched input field element.
24+
*
25+
* Example:
26+
* cy.getFormInputFieldById('name');
27+
* cy.getFormInputFieldById('name', 'text');
28+
*/
29+
Cypress.Commands.add('getFormInputFieldById', (inputId, type = 'text') =>
30+
cy.get(`#main-content .bx--form input#${inputId}[type="${type}"]`)
31+
);
32+
33+
/**
34+
* Retrieves a form label associated with a specific input field by its ID.
35+
*
36+
* @param {string} inputId - The ID of the input field.
37+
* @returns {Element} The matched label element.
38+
*
39+
* Example:
40+
* cy.getFormLabelByInputId('name');
41+
*/
42+
Cypress.Commands.add('getFormLabelByInputId', (inputId) =>
43+
cy.get(`#main-content .bx--form label[for="${inputId}"]`)
44+
);
45+
46+
/**
47+
* Retrieves a form select field by its ID.
48+
*
49+
* @param {string} selectId - The ID of the select field.
50+
* @returns {Element} The matched select field element.
51+
*
52+
* Example:
53+
* cy.getFormSelectFieldById('select-scan-limit');
54+
*/
55+
Cypress.Commands.add('getFormSelectFieldById', (selectId) =>
56+
cy.get(`#main-content .bx--form select#${selectId}`)
57+
);

cypress/support/e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
// Commands
4343
import './commands/explorer.js'
44+
import './commands/element_selectors.js';
4445
import './commands/gtl.js'
4546
import './commands/login.js'
4647
import './commands/menu.js'

0 commit comments

Comments
 (0)