Skip to content

Commit 5287494

Browse files
Replaced repeated form selectors with custom getter commands
1 parent ce4db46 commit 5287494

File tree

1 file changed

+64
-47
lines changed

1 file changed

+64
-47
lines changed

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

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -180,30 +180,32 @@ function addSchedule() {
180180
// Open add schedule form
181181
selectConfigMenu(addScheduleConfigOption);
182182
// Checks if Save button is disabled initially
183-
cy.getFormFooterButtonByType(saveButton, 'submit').should(
184-
'be.disabled'
185-
);
183+
cy.getFormFooterButtonByType(saveButton, 'submit').should('be.disabled');
186184
// Adding data
187185
cy.getFormInputFieldById(nameInputFieldId).type(initialScheduleName);
188186
cy.getFormInputFieldById(descriptionInputFieldId).type(initialDescription);
189187
cy.getFormInputFieldById(activeCheckboxFieldId, 'checkbox').check({
190188
force: true,
191189
});
192190
// Select Action type option: 'VM Analysis'
193-
cy.get('select#action_typ').select(actionTypeVmAnalysis);
191+
cy.getFormSelectFieldById(actionTypeSelectFieldId).select(
192+
actionTypeVmAnalysis
193+
);
194194
// Select Filter type option: 'A Single VM'
195-
cy.get('select#filter_typ').select(actionTypeVmAnalysis);
195+
cy.getFormSelectFieldById(filterTypeSelectFieldId).select(
196+
actionTypeVmAnalysis
197+
);
196198
// Select Run option: 'Hours'
197-
cy.get('select#timer_typ').select(timerTypeHourly);
199+
cy.getFormSelectFieldById(timerTypeSelectFieldId).select(timerTypeHourly);
198200
// Select Every option: '1 Hour'
199-
cy.get('select#timer_value').select(frequencyTypeHour);
201+
cy.getFormSelectFieldById(timerValueSelectFieldId).select(frequencyTypeHour);
200202
// Select Time zone option: '(GMT-10:00) Hawaii'
201-
cy.get('input[role="combobox"]#time_zone').click();
203+
cy.getFormInputFieldById(timeZoneInputFieldId).click();
202204
cy.contains('[role="option"]', timezoneTypeHawaii)
203205
.should('be.visible')
204206
.click();
205-
cy.get('input#start_date').type(initialStartDate);
206-
cy.get('input#start_time').type(startTime);
207+
cy.getFormInputFieldById(startDateInputFieldId).type(initialStartDate);
208+
cy.getFormInputFieldById(startTimeInputFieldId).type(startTime);
207209
// Intercepting the API call for adding a new schedule
208210
cy.interceptApi({
209211
alias: 'addScheduleApi',
@@ -276,33 +278,33 @@ function invokeCleanupDeletion() {
276278
}
277279

278280
function selectAndAssertDropdownValue(id, value) {
279-
cy.get(`select#${id}`).select(value);
280-
cy.get(`select#${id}`).should('have.value', value);
281+
cy.getFormSelectFieldById(id).select(value);
282+
cy.getFormSelectFieldById(id).should('have.value', value);
281283
}
282284

283285
function assertSelectFieldWithLabel(id) {
284-
cy.get(`label[for="${id}"]`).should('exist');
285-
cy.get(`select#${id}`).should('exist');
286+
cy.getFormLabelByInputId(id).should('exist');
287+
cy.getFormSelectFieldById(id).should('exist');
286288
}
287289

288290
function selectActionTypeAndAssertFilterTypeDropdown(value) {
289-
selectAndAssertDropdownValue('action_typ', value);
290-
assertSelectFieldWithLabel('filter_typ');
291+
selectAndAssertDropdownValue(actionTypeSelectFieldId, value);
292+
assertSelectFieldWithLabel(filterTypeSelectFieldId);
291293
}
292294

293295
function selectTimerTypeAndAssertTimerDropdown(value) {
294-
selectAndAssertDropdownValue('timer_typ', value);
295-
assertSelectFieldWithLabel('timer_value');
296+
selectAndAssertDropdownValue(timerTypeSelectFieldId, value);
297+
assertSelectFieldWithLabel(timerValueSelectFieldId);
296298
}
297299

298300
function assertComboboxWithLabel(id) {
299-
cy.get(`label[for="${id}"]`).should('exist');
300-
cy.get(`input[role="combobox"]#${id}`).should('exist');
301+
cy.getFormLabelByInputId(id).should('exist');
302+
cy.getFormInputFieldById(id).should('exist');
301303
}
302304

303305
function assertInputFieldWithLabel(id) {
304-
cy.get(`label[for="${id}"]`).should('exist');
305-
cy.get(`input#${id}`).should('exist');
306+
cy.getFormLabelByInputId(id).should('exist');
307+
cy.getFormInputFieldById(id).should('exist');
306308
}
307309

308310
describe('Automate Schedule form operations: Settings > Application Settings > Settings > Schedules > Configuration > Add a new schedule', () => {
@@ -353,46 +355,49 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
353355

354356
/* ===== Selecting "Automation Tasks" option from "Action" dropdown shows Zone, Object details & Object fields ===== */
355357

356-
selectAndAssertDropdownValue('action_typ', actionTypeAutomationTasks);
358+
selectAndAssertDropdownValue(
359+
actionTypeSelectFieldId,
360+
actionTypeAutomationTasks
361+
);
357362

358363
// Checking for Zone dropdown
359-
assertSelectFieldWithLabel('zone_id');
364+
assertSelectFieldWithLabel(zoneSelectFieldId);
360365

361366
// Checking for Object Details
362367
cy.get('h3[name="object_details"]').should('exist');
363368
// Checking for System/Process dropdown
364-
assertSelectFieldWithLabel('instance_name');
369+
assertSelectFieldWithLabel(systemSelectFieldId);
365370
// Checking for Messsage textfield
366-
assertInputFieldWithLabel('message');
371+
assertInputFieldWithLabel(messageInputFieldId);
367372
// Checking for Request textfield
368-
assertInputFieldWithLabel('request');
373+
assertInputFieldWithLabel(requestInputFieldId);
369374

370375
// Checking for Object
371376
cy.get('h3[name="object_attributes"]').should('exist');
372377
// Checking for Type Combobox
373-
assertComboboxWithLabel('target_class');
378+
assertComboboxWithLabel(typeInputFieldId);
374379
// Checking for Object Combobox
375-
assertComboboxWithLabel('target_id');
380+
assertComboboxWithLabel(objectInputFieldId);
376381

377382
// Checking for Attribute/Value pairs
378383
cy.contains('h3', 'Attribute/Value Pairs').should('exist');
379384
// Checking for 5 attribute-value pairs text fields
380-
cy.get('input#attribute_1').should('exist');
381-
cy.get('input#value_1').should('exist');
382-
cy.get('input#attribute_2').should('exist');
383-
cy.get('input#value_2').should('exist');
384-
cy.get('input#attribute_3').should('exist');
385-
cy.get('input#value_3').should('exist');
386-
cy.get('input#attribute_4').should('exist');
387-
cy.get('input#value_4').should('exist');
388-
cy.get('input#attribute_5').should('exist');
389-
cy.get('input#value_5').should('exist');
385+
cy.getFormInputFieldById('attribute_1').should('exist');
386+
cy.getFormInputFieldById('value_1').should('exist');
387+
cy.getFormInputFieldById('attribute_2').should('exist');
388+
cy.getFormInputFieldById('value_2').should('exist');
389+
cy.getFormInputFieldById('attribute_3').should('exist');
390+
cy.getFormInputFieldById('value_3').should('exist');
391+
cy.getFormInputFieldById('attribute_4').should('exist');
392+
cy.getFormInputFieldById('value_4').should('exist');
393+
cy.getFormInputFieldById('attribute_5').should('exist');
394+
cy.getFormInputFieldById('value_5').should('exist');
390395

391396
/* ===== Selecting "Once" option from "Run" dropdown does not show the "Every" dropdown ===== */
392397

393-
selectAndAssertDropdownValue('timer_typ', timerTypeOnce);
398+
selectAndAssertDropdownValue(timerTypeSelectFieldId, timerTypeOnce);
394399
// Checking whether the Every dropdown is hidden
395-
cy.get('input#timer_value').should('not.exist');
400+
cy.getFormInputFieldById(timerValueSelectFieldId).should('not.exist');
396401

397402
/* ===== Selecting any other option other than "Once" from "Run" dropdown shows the "Every" dropdown ===== */
398403
// Selecting "Hourly" to verify timer dropdown
@@ -424,8 +429,10 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
424429
// Open edit schedule form
425430
selectConfigMenu(editScheduleConfigOption);
426431
// Editing name and description
427-
cy.get('input#name').clear().type(editedScheduleName);
428-
cy.get('input#description').clear().type(editedDescription);
432+
cy.getFormInputFieldById(nameInputFieldId).clear().type(editedScheduleName);
433+
cy.getFormInputFieldById(descriptionInputFieldId)
434+
.clear()
435+
.type(editedDescription);
429436
// Confirms Save button is enabled after making edits
430437
cy.getFormFooterButtonByType(saveButton, 'submit')
431438
.should('be.enabled')
@@ -445,14 +452,24 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
445452
// Open edit schedule form
446453
selectConfigMenu(editScheduleConfigOption);
447454
// Editing description and start date
448-
cy.get('input#description').clear().type(editedDescription);
449-
cy.get('input#start_date').clear().type(editedStartDate);
455+
cy.getFormInputFieldById(descriptionInputFieldId)
456+
.clear()
457+
.type(editedDescription);
458+
cy.getFormInputFieldById(startDateInputFieldId)
459+
.clear()
460+
.type(editedStartDate);
450461
// Resetting
451462
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
452463
cy.expect_flash(flashClassMap.warning, flashMessageResetSchedule);
453464
// Confirming the edited fields contain the old values after resetting
454-
cy.get('input#description').should('have.value', initialDescription);
455-
cy.get('input#start_date').should('have.value', initialStartDate);
465+
cy.getFormInputFieldById(descriptionInputFieldId).should(
466+
'have.value',
467+
initialDescription
468+
);
469+
cy.getFormInputFieldById(startDateInputFieldId).should(
470+
'have.value',
471+
initialStartDate
472+
);
456473

457474
/* ===== Checking whether Cancel button works ===== */
458475
cy.getFormFooterButtonByType(cancelButton).should('be.enabled').click();

0 commit comments

Comments
 (0)