Skip to content

Commit 8afddae

Browse files
Replaced repeated form selectors with custom getter commands
1 parent 3fb1448 commit 8afddae

File tree

1 file changed

+24
-39
lines changed
  • cypress/e2e/ui/Settings/Application-Settings

1 file changed

+24
-39
lines changed

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

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ const textConstants = {
3636
ipInputFieldId: 'settings\\.proxy_server_ip',
3737
maxScanSelectFieldId: 'settings\\.concurrent_vm_scans',
3838

39-
// Common selectors
40-
inputFieldLabelSelector: (forValue) =>
41-
`#main-content .bx--form label[for="${forValue}"]`,
42-
inputFieldSelector: (inputId) => `#main-content .bx--form input#${inputId}`,
43-
selectFieldSelector: (selectId) => `#main-content .bx--form select#${selectId}`,
44-
buttonSelector: (type) => `#main-content .bx--btn-set button[type="${type}"]`,
45-
4639
// Buttons
4740
saveButton: 'Save',
4841
cancelButton: 'Cancel',
@@ -70,10 +63,6 @@ const {
7063
addZoneConfigOption,
7164
editZoneConfigOption,
7265
deleteZoneConfigOption,
73-
selectFieldSelector,
74-
buttonSelector,
75-
inputFieldSelector,
76-
inputFieldLabelSelector,
7766
cancelButton,
7867
addButton,
7968
saveButton,
@@ -104,12 +93,12 @@ function addZone() {
10493
// Open add form
10594
cy.toolbar(configToolbarButton, addZoneConfigOption);
10695
// Adding name, description, ip and scan limit
107-
cy.get(inputFieldSelector(nameInputFieldId)).type(zoneName);
108-
cy.get(inputFieldSelector(descriptionInputFieldId)).type(
96+
cy.getFormInputFieldById(nameInputFieldId).type(zoneName);
97+
cy.getFormInputFieldById(descriptionInputFieldId).type(
10998
initialZoneDescription
11099
);
111-
cy.get(inputFieldSelector(ipInputFieldId)).type(initialServerIp);
112-
cy.get(selectFieldSelector(maxScanSelectFieldId)).select(initialMaxScanLimit);
100+
cy.getFormInputFieldById(ipInputFieldId).type(initialServerIp);
101+
cy.getFormSelectFieldById(maxScanSelectFieldId).select(initialMaxScanLimit);
113102
cy.intercept('POST', '/api/zones').as('createZone');
114103
cy.getFormFooterButtonByType(addButton, 'submit')
115104
.should('be.enabled')
@@ -123,9 +112,9 @@ function validateFormElements(isEditForm = false) {
123112
// Assert Info sub header is visible
124113
cy.get('#main-content .bx--form h3').contains(infoSubHeader);
125114
// Assert name field label is visible
126-
cy.get(inputFieldLabelSelector(nameInputFieldId)).should('be.visible');
115+
cy.getFormLabelByInputId(nameInputFieldId).should('be.visible');
127116
// Assert name field is visible and enabled
128-
cy.get(inputFieldSelector(nameInputFieldId))
117+
cy.getFormInputFieldById(nameInputFieldId)
129118
.should('be.visible')
130119
.then((nameField) => {
131120
if (isEditForm) {
@@ -135,32 +124,32 @@ function validateFormElements(isEditForm = false) {
135124
}
136125
});
137126
// Assert description field label is visible
138-
cy.get(inputFieldLabelSelector(descriptionInputFieldId)).should('be.visible');
127+
cy.getFormLabelByInputId(descriptionInputFieldId).should('be.visible');
139128
// Assert description field is visible and enabled
140-
cy.get(inputFieldSelector(descriptionInputFieldId))
129+
cy.getFormInputFieldById(descriptionInputFieldId)
141130
.should('be.visible')
142131
.and('be.enabled');
143132
// Assert IP field label is visible
144-
cy.get(inputFieldLabelSelector(ipInputFieldId)).should('be.visible');
133+
cy.getFormLabelByInputId(ipInputFieldId).should('be.visible');
145134
// Assert IP field is visible and enabled
146-
cy.get(inputFieldSelector(ipInputFieldId))
135+
cy.getFormInputFieldById(ipInputFieldId)
147136
.should('be.visible')
148137
.and('be.enabled');
149138
// Assert Settings sub header is visible
150139
cy.get('#main-content .bx--form h3').contains(settingsSubHeader);
151140
// Assert max scan field label is visible
152-
cy.get(inputFieldLabelSelector(maxScanSelectFieldId)).should('be.visible');
141+
cy.getFormLabelByInputId(maxScanSelectFieldId).should('be.visible');
153142
// Assert max scan field is visible and enabled
154-
cy.get(selectFieldSelector(maxScanSelectFieldId))
143+
cy.getFormSelectFieldById(maxScanSelectFieldId)
155144
.should('be.visible')
156145
.and('be.enabled');
157146
// Assert cancel button is visible and enabled
158-
cy.contains(buttonSelector(normalButtonType), cancelButton)
147+
cy.getFormFooterButtonByType(cancelButton)
159148
.should('be.visible')
160149
.and('be.enabled');
161150
if (isEditForm) {
162151
// Assert reset button is visible and disabled
163-
cy.contains(buttonSelector(normalButtonType), resetButton)
152+
cy.getFormFooterButtonByType(resetButton)
164153
.should('be.visible')
165154
.and('be.disabled');
166155
}
@@ -216,7 +205,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
216205
// Open add form
217206
cy.toolbar(configToolbarButton, addZoneConfigOption);
218207
// Cancelling the form
219-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
208+
cy.getFormFooterButtonByType(cancelButton).click();
220209
cy.expect_flash(flashTypeWarning, flashMessageOperationCanceled);
221210
});
222211

@@ -238,12 +227,10 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
238227
// Open edit form
239228
cy.toolbar(configToolbarButton, editZoneConfigOption);
240229
// Update IP & scan limit
241-
cy.get(inputFieldSelector(descriptionInputFieldId))
230+
cy.getFormInputFieldById(descriptionInputFieldId)
242231
.clear()
243232
.type(updatedServerIp);
244-
cy.get(selectFieldSelector(maxScanSelectFieldId)).select(
245-
updatedMaxScanLimit
246-
);
233+
cy.getFormSelectFieldById(maxScanSelectFieldId).select(updatedMaxScanLimit);
247234
// Save the form
248235
cy.getFormFooterButtonByType(saveButton, 'submit')
249236
.should('be.enabled')
@@ -276,7 +263,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
276263
// Validate fields
277264
validateFormElements(true);
278265
// Cancelling the form
279-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
266+
cy.getFormFooterButtonByType(cancelButton).click();
280267
});
281268

282269
it('Checking whether cancel & reset buttons work on the edit form', () => {
@@ -295,27 +282,25 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
295282
cy.toolbar(configToolbarButton, editZoneConfigOption);
296283
/* ===== Reset ===== */
297284
// Update description & IP
298-
cy.get(inputFieldSelector(descriptionInputFieldId))
285+
cy.getFormInputFieldById(descriptionInputFieldId)
299286
.clear()
300287
.type(updatedZoneDescription);
301-
cy.get(inputFieldSelector(ipInputFieldId)).clear().type(updatedServerIp);
288+
cy.getFormInputFieldById(ipInputFieldId).clear().type(updatedServerIp);
302289
// Resetting the form
303-
cy.contains(buttonSelector(normalButtonType), resetButton)
304-
.should('be.enabled')
305-
.click();
290+
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
306291
cy.expect_flash(flashTypeWarning, flashMessageOperationReset);
307292
// Confirming the edited fields contain the old values after resetting
308-
cy.get(inputFieldSelector(descriptionInputFieldId)).should(
293+
cy.getFormInputFieldById(descriptionInputFieldId).should(
309294
'have.value',
310295
initialZoneDescription
311296
);
312-
cy.get(inputFieldSelector(ipInputFieldId)).should(
297+
cy.getFormInputFieldById(ipInputFieldId).should(
313298
'have.value',
314299
initialServerIp
315300
);
316301
/* ===== Cancel ===== */
317302
// Cancelling the form
318-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
303+
cy.getFormFooterButtonByType(cancelButton).click();
319304
cy.expect_flash(flashTypeWarning, flashMessageOperationCanceled);
320305
});
321306

0 commit comments

Comments
 (0)