Skip to content

Commit a04994e

Browse files
Replaced repeated form selectors with custom getter commands
1 parent 80cd64a commit a04994e

File tree

1 file changed

+66
-59
lines changed

1 file changed

+66
-59
lines changed

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

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,24 @@ function addSchedule() {
203203
force: true,
204204
});
205205
// Select Action type option: 'VM Analysis'
206-
cy.get('select#action_typ').select(actionTypeVmAnalysis);
206+
cy.getFormSelectFieldById(actionTypeSelectFieldId).select(
207+
actionTypeVmAnalysis
208+
);
207209
// Select Filter type option: 'A Single VM'
208-
cy.get('select#filter_typ').select(actionTypeVmAnalysis);
210+
cy.getFormSelectFieldById(filterTypeSelectFieldId).select(
211+
actionTypeVmAnalysis
212+
);
209213
// Select Run option: 'Hours'
210-
cy.get('select#timer_typ').select(timerTypeHourly);
214+
cy.getFormSelectFieldById(timerTypeSelectFieldId).select(timerTypeHourly);
211215
// Select Every option: '1 Hour'
212-
cy.get('select#timer_value').select(frequencyTypeHour);
216+
cy.getFormSelectFieldById(timerValueSelectFieldId).select(frequencyTypeHour);
213217
// Select Time zone option: '(GMT-10:00) Hawaii'
214-
cy.get('input[role="combobox"]#time_zone').click();
218+
cy.getFormInputFieldById(timeZoneInputFieldId).click();
215219
cy.contains('[role="option"]', timezoneTypeHawaii)
216220
.should('be.visible')
217221
.click();
218-
cy.get('input#start_date').type(initialStartDate);
219-
cy.get('input#start_time').type(startTime);
222+
cy.getFormInputFieldById(startDateInputFieldId).type(initialStartDate);
223+
cy.getFormInputFieldById(startTimeInputFieldId).type(startTime);
220224
// Intercepting the API call for adding a new schedule
221225
cy.intercept('POST', '/ops/schedule_edit/new?button=save').as(
222226
'addScheduleApi'
@@ -287,33 +291,33 @@ function invokeCleanupDeletion() {
287291
}
288292

289293
function selectAndAssertDropdownValue(id, value) {
290-
cy.get(`select#${id}`).select(value);
291-
cy.get(`select#${id}`).should('have.value', value);
294+
cy.getFormSelectFieldById(id).select(value);
295+
cy.getFormSelectFieldById(id).should('have.value', value);
292296
}
293297

294298
function assertSelectFieldWithLabel(id) {
295-
cy.get(`label[for="${id}"]`).should('exist');
296-
cy.get(`select#${id}`).should('exist');
299+
cy.getFormLabelByInputId(id).should('exist');
300+
cy.getFormSelectFieldById(id).should('exist');
297301
}
298302

299303
function selectActionTypeAndAssertFilterTypeDropdown(value) {
300-
selectAndAssertDropdownValue('action_typ', value);
301-
assertSelectFieldWithLabel('filter_typ');
304+
selectAndAssertDropdownValue(actionTypeSelectFieldId, value);
305+
assertSelectFieldWithLabel(filterTypeSelectFieldId);
302306
}
303307

304308
function selectTimerTypeAndAssertTimerDropdown(value) {
305-
selectAndAssertDropdownValue('timer_typ', value);
306-
assertSelectFieldWithLabel('timer_value');
309+
selectAndAssertDropdownValue(timerTypeSelectFieldId, value);
310+
assertSelectFieldWithLabel(timerValueSelectFieldId);
307311
}
308312

309313
function assertComboboxWithLabel(id) {
310-
cy.get(`label[for="${id}"]`).should('exist');
311-
cy.get(`input[role="combobox"]#${id}`).should('exist');
314+
cy.getFormLabelByInputId(id).should('exist');
315+
cy.getFormInputFieldById(id).should('exist');
312316
}
313317

314318
function assertInputFieldWithLabel(id) {
315-
cy.get(`label[for="${id}"]`).should('exist');
316-
cy.get(`input#${id}`).should('exist');
319+
cy.getFormLabelByInputId(id).should('exist');
320+
cy.getFormInputFieldById(id).should('exist');
317321
}
318322

319323
describe('Automate Schedule form operations: Settings > Application Settings > Settings > Schedules > Configuration > Add a new schedule', () => {
@@ -362,46 +366,49 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
362366

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

365-
selectAndAssertDropdownValue('action_typ', actionTypeAutomationTasks);
369+
selectAndAssertDropdownValue(
370+
actionTypeSelectFieldId,
371+
actionTypeAutomationTasks
372+
);
366373

367374
// Checking for Zone dropdown
368-
assertSelectFieldWithLabel('zone_id');
375+
assertSelectFieldWithLabel(zoneSelectFieldId);
369376

370377
// Checking for Object Details
371378
cy.get('h3[name="object_details"]').should('exist');
372379
// Checking for System/Process dropdown
373-
assertSelectFieldWithLabel('instance_name');
380+
assertSelectFieldWithLabel(systemSelectFieldId);
374381
// Checking for Messsage textfield
375-
assertInputFieldWithLabel('message');
382+
assertInputFieldWithLabel(messageInputFieldId);
376383
// Checking for Request textfield
377-
assertInputFieldWithLabel('request');
384+
assertInputFieldWithLabel(requestInputFieldId);
378385

379386
// Checking for Object
380387
cy.get('h3[name="object_attributes"]').should('exist');
381388
// Checking for Type Combobox
382-
assertComboboxWithLabel('target_class');
389+
assertComboboxWithLabel(typeInputFieldId);
383390
// Checking for Object Combobox
384-
assertComboboxWithLabel('target_id');
391+
assertComboboxWithLabel(objectInputFieldId);
385392

386393
// Checking for Attribute/Value pairs
387394
cy.contains('h3', 'Attribute/Value Pairs').should('exist');
388395
// Checking for 5 attribute-value pairs text fields
389-
cy.get('input#attribute_1').should('exist');
390-
cy.get('input#value_1').should('exist');
391-
cy.get('input#attribute_2').should('exist');
392-
cy.get('input#value_2').should('exist');
393-
cy.get('input#attribute_3').should('exist');
394-
cy.get('input#value_3').should('exist');
395-
cy.get('input#attribute_4').should('exist');
396-
cy.get('input#value_4').should('exist');
397-
cy.get('input#attribute_5').should('exist');
398-
cy.get('input#value_5').should('exist');
396+
cy.getFormInputFieldById('attribute_1').should('exist');
397+
cy.getFormInputFieldById('value_1').should('exist');
398+
cy.getFormInputFieldById('attribute_2').should('exist');
399+
cy.getFormInputFieldById('value_2').should('exist');
400+
cy.getFormInputFieldById('attribute_3').should('exist');
401+
cy.getFormInputFieldById('value_3').should('exist');
402+
cy.getFormInputFieldById('attribute_4').should('exist');
403+
cy.getFormInputFieldById('value_4').should('exist');
404+
cy.getFormInputFieldById('attribute_5').should('exist');
405+
cy.getFormInputFieldById('value_5').should('exist');
399406

400407
/* ===== Selecting "Once" option from "Run" dropdown does not show the "Every" dropdown ===== */
401408

402-
selectAndAssertDropdownValue('timer_typ', timerTypeOnce);
409+
selectAndAssertDropdownValue(timerTypeSelectFieldId, timerTypeOnce);
403410
// Checking whether the Every dropdown is hidden
404-
cy.get('input#timer_value').should('not.exist');
411+
cy.getFormInputFieldById(timerValueSelectFieldId).should('not.exist');
405412

406413
/* ===== Selecting any other option other than "Once" from "Run" dropdown shows the "Every" dropdown ===== */
407414
// Selecting "Hourly" to verify timer dropdown
@@ -418,12 +425,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
418425
// Open add schedule form
419426
selectConfigMenu(addScheduleConfigOption);
420427
// Cancel the form
421-
cy.contains(
422-
'#main-content .bx--btn-set button[type="button"]',
423-
cancelButton
424-
)
425-
.should('be.enabled')
426-
.click();
428+
cy.getFormFooterButtonByType(cancelButton).should('be.enabled').click();
427429
cy.expect_flash(flashTypeSuccess, flashMessageOperationCanceled);
428430
});
429431

@@ -438,8 +440,10 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
438440
// Open edit schedule form
439441
selectConfigMenu(editScheduleConfigOption);
440442
// Editing name and description
441-
cy.get('input#name').clear().type(editedScheduleName);
442-
cy.get('input#description').clear().type(editedDescription);
443+
cy.getFormInputFieldById(nameInputFieldId).clear().type(editedScheduleName);
444+
cy.getFormInputFieldById(descriptionInputFieldId)
445+
.clear()
446+
.type(editedDescription);
443447
// Confirms Save button is enabled after making edits
444448
cy.getFormFooterButtonByType(saveButton, 'submit')
445449
.should('be.enabled')
@@ -459,24 +463,27 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
459463
// Open edit schedule form
460464
selectConfigMenu(editScheduleConfigOption);
461465
// Editing description and start date
462-
cy.get('input#description').clear().type(editedDescription);
463-
cy.get('input#start_date').clear().type(editedStartDate);
466+
cy.getFormInputFieldById(descriptionInputFieldId)
467+
.clear()
468+
.type(editedDescription);
469+
cy.getFormInputFieldById(startDateInputFieldId)
470+
.clear()
471+
.type(editedStartDate);
464472
// Resetting
465-
cy.contains('#main-content .bx--btn-set button[type="button"]', resetButton)
466-
.should('be.enabled')
467-
.click();
473+
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
468474
cy.expect_flash(flashTypeWarning, flashMessageResetSchedule);
469475
// Confirming the edited fields contain the old values after resetting
470-
cy.get('input#description').should('have.value', initialDescription);
471-
cy.get('input#start_date').should('have.value', initialStartDate);
476+
cy.getFormInputFieldById(descriptionInputFieldId).should(
477+
'have.value',
478+
initialDescription
479+
);
480+
cy.getFormInputFieldById(startDateInputFieldId).should(
481+
'have.value',
482+
initialStartDate
483+
);
472484

473485
/* ===== Checking whether Cancel button works ===== */
474-
cy.contains(
475-
'#main-content .bx--btn-set button[type="button"]',
476-
cancelButton
477-
)
478-
.should('be.enabled')
479-
.click();
486+
cy.getFormFooterButtonByType(cancelButton).should('be.enabled').click();
480487
cy.expect_flash(flashTypeSuccess, flashMessageOperationCanceled);
481488
});
482489

0 commit comments

Comments
 (0)