Skip to content

Commit 0d14fa8

Browse files
Replaced repeated form selectors with custom getter commands
1 parent b447040 commit 0d14fa8

File tree

1 file changed

+32
-52
lines changed

1 file changed

+32
-52
lines changed

cypress/e2e/ui/Automation/Embedded-Automate/Explorer/namespace.cy.js

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,13 @@ const textConstants = {
1313
toolbarEditNamespace: 'Edit this Namespace',
1414
toolbarRemoveNamespace: 'Remove this Namespace',
1515

16-
// Common selectors
17-
inputFieldSelector: (inputId) =>
18-
`#main-content #datastore-form-wrapper input#${inputId}`,
19-
buttonSelector: (type) => `#main-content .bx--btn-set button[type="${type}"]`,
20-
inputFieldLabelSelector: (forValue) =>
21-
`#main-content #datastore-form-wrapper label[for="${forValue}"]`,
22-
2316
// Element ids
2417
nameInputFieldId: 'name',
2518
descriptionInputFieldId: 'description',
2619
namespacePathInputFieldId: 'namespacePath',
2720

2821
// Button types
2922
submitButtonType: 'submit',
30-
normalButtonType: 'button',
3123

3224
// Field values
3325
domainName: 'Test_Domain',
@@ -68,9 +60,6 @@ const {
6860
automationMenuOption,
6961
embeddedAutomationMenuOption,
7062
explorerMenuOption,
71-
inputFieldSelector,
72-
buttonSelector,
73-
inputFieldLabelSelector,
7463
addButton,
7564
cancelButton,
7665
resetButton,
@@ -104,16 +93,15 @@ const {
10493
descriptionInputFieldId,
10594
namespacePathInputFieldId,
10695
submitButtonType,
107-
normalButtonType,
10896
} = textConstants;
10997

11098
function addNamespace(nameFieldValue = namespaceName) {
11199
// Navigating to the Add Namespace form
112100
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
113101
// Creating a new namespace
114-
cy.get(inputFieldSelector(nameInputFieldId)).type(nameFieldValue);
115-
cy.get(inputFieldSelector(descriptionInputFieldId)).type(description);
116-
cy.contains(buttonSelector(submitButtonType), addButton).click();
102+
cy.getFormInputFieldById(nameInputFieldId).type(nameFieldValue);
103+
cy.getFormInputFieldById(descriptionInputFieldId).type(description);
104+
cy.getFormFooterButtonByType(addButton, submitButtonType).click();
117105
cy.wait('@addNamespaceApi');
118106
}
119107

@@ -141,41 +129,39 @@ function validateNamespaceFormFields(isEditForm = false) {
141129
namespaceFormSubHeader
142130
);
143131
// Assert name-space path field label is visible
144-
cy.get(inputFieldLabelSelector(namespacePathInputFieldId)).should(
145-
'be.visible'
146-
);
132+
cy.getFormLabelByInputId(namespacePathInputFieldId).should('be.visible');
147133
// Assert name-space path field is visible and disabled
148-
cy.get(inputFieldSelector(namespacePathInputFieldId))
134+
cy.getFormInputFieldById(namespacePathInputFieldId)
149135
.should('be.visible')
150136
.and('be.disabled')
151137
.invoke('val')
152138
.should('include', domainName);
153139
// Assert name field label is visible
154-
cy.get(inputFieldLabelSelector(nameInputFieldId)).should('be.visible');
140+
cy.getFormLabelByInputId(nameInputFieldId).should('be.visible');
155141
// Assert name field is visible and enabled
156-
cy.get(inputFieldSelector(nameInputFieldId))
142+
cy.getFormInputFieldById(nameInputFieldId)
157143
.should('be.visible')
158144
.and('be.enabled');
159145
// Assert description field label is visible
160-
cy.get(inputFieldLabelSelector(descriptionInputFieldId)).should('be.visible');
146+
cy.getFormLabelByInputId(descriptionInputFieldId).should('be.visible');
161147
// Assert description field is visible and enabled
162-
cy.get(inputFieldSelector(descriptionInputFieldId))
148+
cy.getFormInputFieldById(descriptionInputFieldId)
163149
.should('be.visible')
164150
.and('be.enabled');
165151
// Assert cancel button is visible and enabled
166-
cy.contains(buttonSelector(normalButtonType), cancelButton)
152+
cy.getFormFooterButtonByType(cancelButton)
167153
.should('be.visible')
168154
.and('be.enabled');
169155
// Assert add/save button is visible and disabled
170-
cy.contains(
171-
buttonSelector(submitButtonType),
172-
isEditForm ? saveButton : addButton
156+
cy.getFormFooterButtonByType(
157+
isEditForm ? saveButton : addButton,
158+
submitButtonType
173159
)
174160
.should('be.visible')
175161
.and('be.disabled');
176162
if (isEditForm) {
177163
// Assert reset button is visible and disabled
178-
cy.contains(buttonSelector(normalButtonType), resetButton)
164+
cy.getFormFooterButtonByType(resetButton)
179165
.should('be.visible')
180166
.and('be.disabled');
181167
}
@@ -229,12 +215,12 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
229215
/* TODO: DATA_SETUP - Refactor to use API for domain data setup */
230216
// Creating a domain to test namespace operations
231217
cy.toolbar(toolbarConfiguration, toolbarAddNewDomain);
232-
cy.get(inputFieldSelector(nameInputFieldId)).type(domainName);
233-
cy.get(inputFieldSelector(descriptionInputFieldId)).type(description);
218+
cy.getFormInputFieldById(nameInputFieldId).type(domainName);
219+
cy.getFormInputFieldById(descriptionInputFieldId).type(description);
234220
cy.intercept('POST', '/miq_ae_class/create_namespace/new?button=add').as(
235221
'addNamespaceApi'
236222
);
237-
cy.contains(buttonSelector(submitButtonType), addButton).click();
223+
cy.getFormFooterButtonByType(addButton, submitButtonType).click();
238224
cy.wait('@addNamespaceApi').then((interception) => {
239225
extractDomainIdAndTokenFromResponse(interception);
240226
});
@@ -251,17 +237,15 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
251237
validateNamespaceFormFields();
252238

253239
// Cancelling the form
254-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
240+
cy.getFormFooterButtonByType(cancelButton).click();
255241
});
256242

257243
it('Validate Cancel button', () => {
258244
// Navigating to the Add Namespace form
259245
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
260246

261247
// Cancelling the form
262-
cy.contains(buttonSelector(normalButtonType), cancelButton)
263-
.should('be.enabled')
264-
.click();
248+
cy.getFormFooterButtonByType(cancelButton).should('be.enabled').click();
265249
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
266250
});
267251

@@ -271,7 +255,7 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
271255
cy.expect_flash(flashTypeError, flashMessageInvalidNamespace);
272256

273257
// Cancelling the form
274-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
258+
cy.getFormFooterButtonByType(cancelButton).click();
275259
});
276260

277261
it('Validate Edit Namespace form fields', () => {
@@ -282,7 +266,7 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
282266
validateNamespaceFormFields(true);
283267

284268
// Cancelling the form
285-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
269+
cy.getFormFooterButtonByType(cancelButton).click();
286270
});
287271

288272
it('Checking whether add, edit & delete namespace works', () => {
@@ -295,13 +279,13 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
295279
// Editing the namespace
296280
cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
297281
// Checking if the Save button is disabled initially
298-
cy.contains(buttonSelector(submitButtonType), saveButton).should(
282+
cy.getFormFooterButtonByType(saveButton, submitButtonType).should(
299283
'be.disabled'
300284
);
301-
cy.get(inputFieldSelector(descriptionInputFieldId))
285+
cy.getFormInputFieldById(descriptionInputFieldId)
302286
.clear()
303287
.type(editedDescription);
304-
cy.contains(buttonSelector(submitButtonType), saveButton)
288+
cy.getFormFooterButtonByType(saveButton, submitButtonType)
305289
.should('be.enabled')
306290
.click();
307291
cy.expect_flash(flashTypeSuccess, flashMessageSaveSuccess);
@@ -324,7 +308,7 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
324308
cy.expect_flash(flashTypeError, flashMessageNameAlreadyExists);
325309

326310
// Cancelling the form
327-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
311+
cy.getFormFooterButtonByType(cancelButton).click();
328312
});
329313

330314
it('Checking whether Cancel & Reset buttons work fine in the Edit form', () => {
@@ -333,33 +317,29 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
333317

334318
/* Validating Reset button */
335319
// Checking if the Reset button is disabled initially
336-
cy.contains(buttonSelector(normalButtonType), resetButton).should(
337-
'be.disabled'
338-
);
320+
cy.getFormFooterButtonByType(resetButton).should('be.disabled');
339321
// Editing name and description fields
340-
cy.get(inputFieldSelector(nameInputFieldId))
322+
cy.getFormInputFieldById(nameInputFieldId)
341323
.clear()
342324
.type(editedNamespaceName);
343-
cy.get(inputFieldSelector(descriptionInputFieldId))
325+
cy.getFormInputFieldById(descriptionInputFieldId)
344326
.clear()
345327
.type(editedDescription);
346328
// Resetting
347-
cy.contains(buttonSelector(normalButtonType), resetButton)
348-
.should('be.enabled')
349-
.click();
329+
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
350330
cy.expect_flash(flashTypeWarning, flashMessageResetNamespace);
351331
// Confirming the edited fields contain the old values after resetting
352-
cy.get(inputFieldSelector(nameInputFieldId)).should(
332+
cy.getFormInputFieldById(nameInputFieldId).should(
353333
'have.value',
354334
namespaceName
355335
);
356-
cy.get(inputFieldSelector(descriptionInputFieldId)).should(
336+
cy.getFormInputFieldById(descriptionInputFieldId).should(
357337
'have.value',
358338
description
359339
);
360340

361341
/* Validating Cancel button */
362-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
342+
cy.getFormFooterButtonByType(cancelButton).click();
363343
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
364344
});
365345

0 commit comments

Comments
 (0)