Skip to content

Commit 3d1b598

Browse files
Replaced repeated form selectors with custom getter commands
1 parent 432ecf8 commit 3d1b598

File tree

1 file changed

+29
-46
lines changed
  • cypress/e2e/ui/Settings/Application-Settings

1 file changed

+29
-46
lines changed

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

Lines changed: 29 additions & 46 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',
@@ -51,7 +44,6 @@ const textConstants = {
5144

5245
// Button types
5346
submitButtonType: 'submit',
54-
normalButtonType: 'button',
5547

5648
// Flash message types
5749
flashTypeSuccess: 'success',
@@ -74,10 +66,6 @@ const {
7466
addZoneConfigOption,
7567
editZoneConfigOption,
7668
deleteZoneConfigOption,
77-
selectFieldSelector,
78-
buttonSelector,
79-
inputFieldSelector,
80-
inputFieldLabelSelector,
8169
cancelButton,
8270
addButton,
8371
saveButton,
@@ -89,7 +77,6 @@ const {
8977
flashMessageOperationReset,
9078
flashMessageZoneUpdated,
9179
submitButtonType,
92-
normalButtonType,
9380
formHeaderFragment,
9481
infoSubHeader,
9582
settingsSubHeader,
@@ -110,14 +97,14 @@ function addZone() {
11097
// Open add form
11198
cy.toolbar(configToolbarButton, addZoneConfigOption);
11299
// Adding name, description, ip and scan limit
113-
cy.get(inputFieldSelector(nameInputFieldId)).type(zoneName);
114-
cy.get(inputFieldSelector(descriptionInputFieldId)).type(
100+
cy.getFormInputFieldById(nameInputFieldId).type(zoneName);
101+
cy.getFormInputFieldById(descriptionInputFieldId).type(
115102
initialZoneDescription
116103
);
117-
cy.get(inputFieldSelector(ipInputFieldId)).type(initialServerIp);
118-
cy.get(selectFieldSelector(maxScanSelectFieldId)).select(initialMaxScanLimit);
104+
cy.getFormInputFieldById(ipInputFieldId).type(initialServerIp);
105+
cy.getFormSelectFieldById(maxScanSelectFieldId).select(initialMaxScanLimit);
119106
cy.intercept('POST', '/api/zones').as('createZone');
120-
cy.contains(buttonSelector(submitButtonType), addButton)
107+
cy.getFormFooterButtonByType(addButton, submitButtonType)
121108
.should('be.enabled')
122109
.click();
123110
cy.wait('@createZone');
@@ -129,9 +116,9 @@ function validateFormElements(isEditForm = false) {
129116
// Assert Info sub header is visible
130117
cy.get('#main-content .bx--form h3').contains(infoSubHeader);
131118
// Assert name field label is visible
132-
cy.get(inputFieldLabelSelector(nameInputFieldId)).should('be.visible');
119+
cy.getFormLabelByInputId(nameInputFieldId).should('be.visible');
133120
// Assert name field is visible and enabled
134-
cy.get(inputFieldSelector(nameInputFieldId))
121+
cy.getFormInputFieldById(nameInputFieldId)
135122
.should('be.visible')
136123
.then((nameField) => {
137124
if (isEditForm) {
@@ -141,39 +128,39 @@ function validateFormElements(isEditForm = false) {
141128
}
142129
});
143130
// Assert description field label is visible
144-
cy.get(inputFieldLabelSelector(descriptionInputFieldId)).should('be.visible');
131+
cy.getFormLabelByInputId(descriptionInputFieldId).should('be.visible');
145132
// Assert description field is visible and enabled
146-
cy.get(inputFieldSelector(descriptionInputFieldId))
133+
cy.getFormInputFieldById(descriptionInputFieldId)
147134
.should('be.visible')
148135
.and('be.enabled');
149136
// Assert IP field label is visible
150-
cy.get(inputFieldLabelSelector(ipInputFieldId)).should('be.visible');
137+
cy.getFormLabelByInputId(ipInputFieldId).should('be.visible');
151138
// Assert IP field is visible and enabled
152-
cy.get(inputFieldSelector(ipInputFieldId))
139+
cy.getFormInputFieldById(ipInputFieldId)
153140
.should('be.visible')
154141
.and('be.enabled');
155142
// Assert Settings sub header is visible
156143
cy.get('#main-content .bx--form h3').contains(settingsSubHeader);
157144
// Assert max scan field label is visible
158-
cy.get(inputFieldLabelSelector(maxScanSelectFieldId)).should('be.visible');
145+
cy.getFormLabelByInputId(maxScanSelectFieldId).should('be.visible');
159146
// Assert max scan field is visible and enabled
160-
cy.get(selectFieldSelector(maxScanSelectFieldId))
147+
cy.getFormSelectFieldById(maxScanSelectFieldId)
161148
.should('be.visible')
162149
.and('be.enabled');
163150
// Assert cancel button is visible and enabled
164-
cy.contains(buttonSelector(normalButtonType), cancelButton)
151+
cy.getFormFooterButtonByType(cancelButton)
165152
.should('be.visible')
166153
.and('be.enabled');
167154
if (isEditForm) {
168155
// Assert reset button is visible and disabled
169-
cy.contains(buttonSelector(normalButtonType), resetButton)
156+
cy.getFormFooterButtonByType(resetButton)
170157
.should('be.visible')
171158
.and('be.disabled');
172159
}
173160
// Assert add/save button is visible and disabled
174-
cy.contains(
175-
buttonSelector(submitButtonType),
176-
isEditForm ? saveButton : addButton
161+
cy.getFormFooterButtonByType(
162+
isEditForm ? saveButton : addButton,
163+
submitButtonType
177164
)
178165
.should('be.visible')
179166
.and('be.disabled');
@@ -225,7 +212,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
225212
// Open add form
226213
cy.toolbar(configToolbarButton, addZoneConfigOption);
227214
// Cancelling the form
228-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
215+
cy.getFormFooterButtonByType(cancelButton).click();
229216
cy.expect_flash(flashTypeWarning, flashMessageOperationCanceled);
230217
});
231218

@@ -245,14 +232,12 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
245232
// Open edit form
246233
cy.toolbar(configToolbarButton, editZoneConfigOption);
247234
// Update IP & scan limit
248-
cy.get(inputFieldSelector(descriptionInputFieldId))
235+
cy.getFormInputFieldById(descriptionInputFieldId)
249236
.clear()
250237
.type(updatedServerIp);
251-
cy.get(selectFieldSelector(maxScanSelectFieldId)).select(
252-
updatedMaxScanLimit
253-
);
238+
cy.getFormSelectFieldById(maxScanSelectFieldId).select(updatedMaxScanLimit);
254239
// Save the form
255-
cy.contains(buttonSelector(submitButtonType), saveButton)
240+
cy.getFormFooterButtonByType(saveButton, submitButtonType)
256241
.should('be.enabled')
257242
.click();
258243
cy.expect_flash(flashTypeSuccess, flashMessageZoneUpdated);
@@ -281,7 +266,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
281266
// Validate fields
282267
validateFormElements(true);
283268
// Cancelling the form
284-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
269+
cy.getFormFooterButtonByType(cancelButton).click();
285270
});
286271

287272
it('Checking whether cancel & reset buttons work on the edit form', () => {
@@ -298,27 +283,25 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
298283
cy.toolbar(configToolbarButton, editZoneConfigOption);
299284
/* ===== Reset ===== */
300285
// Update description & IP
301-
cy.get(inputFieldSelector(descriptionInputFieldId))
286+
cy.getFormInputFieldById(descriptionInputFieldId)
302287
.clear()
303288
.type(updatedZoneDescription);
304-
cy.get(inputFieldSelector(ipInputFieldId)).clear().type(updatedServerIp);
289+
cy.getFormInputFieldById(ipInputFieldId).clear().type(updatedServerIp);
305290
// Resetting the form
306-
cy.contains(buttonSelector(normalButtonType), resetButton)
307-
.should('be.enabled')
308-
.click();
291+
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
309292
cy.expect_flash(flashTypeWarning, flashMessageOperationReset);
310293
// Confirming the edited fields contain the old values after resetting
311-
cy.get(inputFieldSelector(descriptionInputFieldId)).should(
294+
cy.getFormInputFieldById(descriptionInputFieldId).should(
312295
'have.value',
313296
initialZoneDescription
314297
);
315-
cy.get(inputFieldSelector(ipInputFieldId)).should(
298+
cy.getFormInputFieldById(ipInputFieldId).should(
316299
'have.value',
317300
initialServerIp
318301
);
319302
/* ===== Cancel ===== */
320303
// Cancelling the form
321-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
304+
cy.getFormFooterButtonByType(cancelButton).click();
322305
cy.expect_flash(flashTypeWarning, flashMessageOperationCanceled);
323306
});
324307

0 commit comments

Comments
 (0)