Skip to content

Commit b10c215

Browse files
Enhanced element selector commands for improved readability
1 parent 2729d56 commit b10c215

File tree

3 files changed

+114
-51
lines changed

3 files changed

+114
-51
lines changed

cypress/e2e/ui/Settings/Application-Settings/edit_collect_logs.cy.js

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,21 @@ function resetProtocolDropdown({ selectServerListItem = true } = {}) {
7171
selectToolbarEditButton();
7272

7373
// Resetting Protocol dropdown value
74-
cy.getFormSelectFieldById('log_protocol').then((selectField) => {
75-
const currentValue = selectField.val();
76-
// If the value is not default one(BLANK_VALUE), then setting it to blank
77-
if (currentValue !== DROPDOWN_BLANK_VALUE) {
78-
cy.wrap(selectField).select(DROPDOWN_BLANK_VALUE);
79-
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit').click();
80-
// Validating confirmation flash message
81-
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SETTINGS_SAVED);
74+
cy.getFormSelectFieldById({ selectId: 'log_protocol' }).then(
75+
(selectField) => {
76+
const currentValue = selectField.val();
77+
// If the value is not default one(BLANK_VALUE), then setting it to blank
78+
if (currentValue !== DROPDOWN_BLANK_VALUE) {
79+
cy.wrap(selectField).select(DROPDOWN_BLANK_VALUE);
80+
cy.getFormFooterButtonByTypeWithText({
81+
buttonText: SAVE_BUTTON_TEXT,
82+
buttonType: 'submit',
83+
}).click();
84+
// Validating confirmation flash message
85+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SETTINGS_SAVED);
86+
}
8287
}
83-
});
88+
);
8489
}
8590

8691
function goToCollectLogsTabAndOpenEditForm() {
@@ -98,49 +103,71 @@ function validateFormElements() {
98103
'be.visible'
99104
);
100105
// Assert protocol field label is visible
101-
cy.getFormLabelByInputId('log_protocol').should('be.visible');
106+
cy.getFormLabelByForAttribute({ forValue: 'log_protocol' }).should(
107+
'be.visible'
108+
);
102109
// Assert protocol field is visible and enabled
103-
cy.getFormSelectFieldById('log_protocol')
110+
cy.getFormSelectFieldById({ selectId: 'log_protocol' })
104111
.should('be.visible')
105112
.and('be.enabled');
106113
// Assert cancel button is visible and enabled
107-
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT)
114+
cy.getFormFooterButtonByTypeWithText({
115+
buttonText: CANCEL_BUTTON_TEXT,
116+
})
108117
.should('be.visible')
109118
.and('be.enabled');
110119
// Assert save button is visible and disabled
111-
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
120+
cy.getFormFooterButtonByTypeWithText({
121+
buttonText: SAVE_BUTTON_TEXT,
122+
buttonType: 'submit',
123+
})
112124
.should('be.visible')
113125
.and('be.disabled');
114126
// Assert reset button is visible and disabled
115-
cy.getFormFooterButtonByType(RESET_BUTTON_TEXT)
127+
cy.getFormFooterButtonByTypeWithText({
128+
buttonText: RESET_BUTTON_TEXT,
129+
})
116130
.should('be.visible')
117131
.and('be.disabled');
118132
}
119133

120134
function cancelButtonValidation() {
121135
// Click cancel button in the form
122-
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT).click();
136+
cy.getFormFooterButtonByTypeWithText({
137+
buttonText: CANCEL_BUTTON_TEXT,
138+
}).click();
123139
// Validating confirmation flash message
124140
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_OPERATION_CANCELLED);
125141
}
126142

127143
function resetButtonValidation() {
128144
// Selecting Samba option from dropdown
129-
cy.getFormSelectFieldById('log_protocol').select(SAMBA_DROPDOWN_VALUE);
145+
cy.getFormSelectFieldById({ selectId: 'log_protocol' }).select(
146+
SAMBA_DROPDOWN_VALUE
147+
);
130148
// Confirm Reset button is enabled once dropdown value is changed and then click on Reset
131-
cy.getFormFooterButtonByType(RESET_BUTTON_TEXT).should('be.enabled').click();
149+
cy.getFormFooterButtonByTypeWithText({
150+
buttonText: RESET_BUTTON_TEXT,
151+
})
152+
.should('be.enabled')
153+
.click();
132154
// Confirm dropdown has the old value
133-
cy.getFormSelectFieldById('log_protocol').should(
155+
cy.getFormSelectFieldById({ selectId: 'log_protocol' }).should(
134156
'have.value',
135157
DROPDOWN_BLANK_VALUE
136158
);
137159
}
138160

139161
function saveButtonValidation() {
140162
// Selecting Samba option from dropdown
141-
cy.getFormSelectFieldById('log_protocol').select(SAMBA_DROPDOWN_VALUE);
163+
cy.getFormSelectFieldById({ selectId: 'log_protocol' }).select(
164+
SAMBA_DROPDOWN_VALUE
165+
);
142166
// Confirm Save button is enabled once dropdown value is changed and then click on Save
143-
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
167+
cy.getFormFooterButtonByTypeWithText({
168+
buttonText: SAVE_BUTTON_TEXT,
169+
buttonType: 'submit',
170+
})
144171
.should('be.enabled')
145172
.click();
146173
// Validating confirmation flash message

cypress/e2e/ui/Settings/Application-Settings/settings_access_control.cy.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ describe('Settings > Application Settings > Access Control', () => {
3131
]);
3232

3333
cy.toolbar(TOOLBAR_MENU, 'Add child Tenant to this Tenant');
34-
cy.getFormInputFieldById('name').type(INITIAL_TENANT_NAME);
35-
cy.getFormInputFieldById('description').type(INITIAL_TENANT_DESCRIPTION);
36-
cy.getFormFooterButtonByType('Add', 'submit').click();
34+
cy.getFormInputFieldByIdAndType({ inputId: 'name' }).type(
35+
INITIAL_TENANT_NAME
36+
);
37+
cy.getFormInputFieldByIdAndType({ inputId: 'description' }).type(
38+
INITIAL_TENANT_DESCRIPTION
39+
);
40+
cy.getFormFooterButtonByTypeWithText({
41+
buttonText: 'Add',
42+
buttonType: 'submit',
43+
}).click();
3744
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_OPERATION_ADDED);
3845
cy.selectAccordionItem([
3946
/^ManageIQ Region/,
Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,86 @@
1-
/* eslint-disable no-undef */
2-
31
/**
4-
* Retrieves a form footer button by its name and type.
2+
* Retrieves a form footer button by its text content and type using an object parameter.
53
*
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'.
4+
* @param {Object} options - The options object.
5+
* @param {string} options.buttonText - The text content of the button (required).
6+
* @param {string} [options.buttonType='button'] - The HTML button type (e.g., 'button', 'submit', 'reset'). Defaults to 'button'.
87
* @returns {Element} The matched button element.
8+
* @throws {Error} If buttonName is not provided.
99
*
1010
* Example:
11-
* cy.getFormFooterButtonByType('Save Changes');
12-
* cy.getFormFooterButtonByType('Reset', 'reset');
11+
* cy.getFormFooterButtonByTypeWithText({ buttonText: 'Save Changes' });
12+
* cy.getFormFooterButtonByTypeWithText({ buttonText: 'Submit', buttonType: 'submit' });
1313
*/
14-
Cypress.Commands.add('getFormFooterButtonByType', (name, type = 'button') =>
15-
cy.contains(`#main-content .bx--btn-set button[type="${type}"]`, name)
14+
Cypress.Commands.add(
15+
'getFormFooterButtonByTypeWithText',
16+
({ buttonType = 'button', buttonText } = {}) => {
17+
if (!buttonText) {
18+
cy.logAndThrowError('buttonName is required');
19+
}
20+
return cy.contains(
21+
`#main-content .bx--btn-set button[type="${buttonType}"]`,
22+
buttonText
23+
);
24+
}
1625
);
1726

1827
/**
19-
* Retrieves a form input field by its ID and type.
28+
* Retrieves a form input field by its ID and type using an object parameter.
2029
*
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'.
30+
* @param {Object} options - The options object.
31+
* @param {string} options.inputId - The ID of the input field (required).
32+
* @param {string} [options.inputType='text'] - The HTML input inputType (e.g., 'text', 'email', 'password'). Defaults to 'text'.
2333
* @returns {Element} The matched input field element.
34+
* @throws {Error} If inputId is not provided.
2435
*
2536
* Example:
26-
* cy.getFormInputFieldById('name');
27-
* cy.getFormInputFieldById('name', 'text');
37+
* cy.getFormInputFieldByIdAndType({ inputId: 'name' });
38+
* cy.getFormInputFieldByIdAndType({ inputId: 'password', inputType: 'password' });
2839
*/
29-
Cypress.Commands.add('getFormInputFieldById', (inputId, type = 'text') =>
30-
cy.get(`#main-content .bx--form input#${inputId}[type="${type}"]`)
40+
Cypress.Commands.add(
41+
'getFormInputFieldByIdAndType',
42+
({ inputId, inputType = 'text' }) => {
43+
if (!inputId) {
44+
cy.logAndThrowError('inputId is required');
45+
}
46+
return cy.get(
47+
`#main-content .bx--form input#${inputId}][type="${inputType}"]`
48+
);
49+
}
3150
);
3251

3352
/**
34-
* Retrieves a form label associated with a specific input field by its ID.
53+
* Retrieves a form label associated with a specific input field by its 'for' attribute.
3554
*
36-
* @param {string} inputId - The ID of the input field.
55+
* @param {Object} options - The options object.
56+
* @param {string} options.forValue - The value of the 'for' attribute that matches the input field's ID (required).
3757
* @returns {Element} The matched label element.
58+
* @throws {Error} If forValue is not provided.
3859
*
3960
* Example:
40-
* cy.getFormLabelByInputId('name');
61+
* cy.getFormLabelByForAttribute({ forValue: 'name' });
4162
*/
42-
Cypress.Commands.add('getFormLabelByInputId', (inputId) =>
43-
cy.get(`#main-content .bx--form label[for="${inputId}"]`)
44-
);
63+
Cypress.Commands.add('getFormLabelByForAttribute', ({ forValue }) => {
64+
if (!forValue) {
65+
cy.logAndThrowError('forValue is required');
66+
}
67+
return cy.get(`#main-content .bx--form label[for="${forValue}"]`);
68+
});
4569

4670
/**
47-
* Retrieves a form select field by its ID.
71+
* Retrieves a form select field by its ID using an object parameter.
4872
*
49-
* @param {string} selectId - The ID of the select field.
73+
* @param {Object} options - The options object.
74+
* @param {string} options.selectId - The ID of the select field (required).
5075
* @returns {Element} The matched select field element.
76+
* @throws {Error} If selectId is not provided.
5177
*
5278
* Example:
53-
* cy.getFormSelectFieldById('select-scan-limit');
79+
* cy.getFormSelectFieldById({ selectId: 'select-scan-limit' });
5480
*/
55-
Cypress.Commands.add('getFormSelectFieldById', (selectId) =>
56-
cy.get(`#main-content .bx--form select#${selectId}`)
57-
);
81+
Cypress.Commands.add('getFormSelectFieldById', ({ selectId }) => {
82+
if (!selectId) {
83+
cy.logAndThrowError('selectId is required');
84+
}
85+
return cy.get(`#main-content .bx--form select#${selectId}]`);
86+
});

0 commit comments

Comments
 (0)