Skip to content

Commit 6877217

Browse files
Replaced repeated form selectors with custom getter commands
1 parent 20d6ab9 commit 6877217

File tree

1 file changed

+130
-133
lines changed

1 file changed

+130
-133
lines changed

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

Lines changed: 130 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,36 @@ function addSchedule() {
7474
// Open add schedule form
7575
selectConfigMenu(ADD_SCHEDULE_CONFIG_OPTION);
7676
// Checks if Save button is disabled initially
77-
cy.contains(
78-
'#main-content .bx--btn-set button[type="submit"]',
79-
saveButton
80-
).should('be.disabled');
77+
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit').should(
78+
'be.disabled'
79+
);
8180
// Adding data
82-
cy.get('input#name').type(initialScheduleName);
83-
cy.get('input#description').type(initialDescription);
84-
cy.get('input[type="checkbox"]#enabled').check({ force: true });
81+
cy.getFormInputFieldById('name').type(INITIAL_SCHEDULE_NAME);
82+
cy.getFormInputFieldById('description').type(INITIAL_DESCRIPTION);
83+
// Check "Active" checkbox using its associated label
84+
cy.getFormLabelByInputId('enabled').click();
8585
// Select Action type option: 'VM Analysis'
86-
cy.get('select#action_typ').select(actionTypeVmAnalysis);
86+
cy.getFormSelectFieldById('action_typ').select(ACTION_TYPE_VM_ANALYSIS);
8787
// Select Filter type option: 'A Single VM'
88-
cy.get('select#filter_typ').select(actionTypeVmAnalysis);
88+
cy.getFormSelectFieldById('filter_typ').select(ACTION_TYPE_VM_ANALYSIS);
8989
// Select Run option: 'Hours'
90-
cy.get('select#timer_typ').select(timerTypeHourly);
90+
cy.getFormSelectFieldById('timer_typ').select(TIMER_TYPE_HOURLY);
9191
// Select Every option: '1 Hour'
92-
cy.get('select#timer_value').select(frequencyTypeHour);
92+
cy.getFormSelectFieldById('timer_value').select(FREQUENCY_TYPE_HOUR);
9393
// Select Time zone option: '(GMT-10:00) Hawaii'
94-
cy.get('input[role="combobox"]#time_zone').click();
95-
cy.contains('[role="option"]', timezoneTypeHawaii)
94+
cy.getFormInputFieldById('time_zone').click();
95+
cy.contains('[role="option"]', TIMEZONE_TYPE_HAWAII)
9696
.should('be.visible')
9797
.click();
98-
cy.get('input#start_date').type(initialStartDate);
99-
cy.get('input#start_time').type(startTime);
98+
cy.getFormInputFieldById('start_date').type(INITIAL_START_DATE);
99+
cy.getFormInputFieldById('start_time').type(START_TIME);
100100
// Intercepting the API call for adding a new schedule
101101
cy.interceptApi({
102102
alias: 'addScheduleApi',
103103
urlPattern: '/ops/schedule_edit/new?button=save',
104104
triggerFn: () =>
105-
cy.contains('#main-content .bx--btn-set button[type="submit"]', saveButton)
105+
cy
106+
.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
106107
.should('be.enabled') // Checks if Save button is enabled once all required fields are filled
107108
.click(),
108109
});
@@ -174,11 +175,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
174175
cy.interceptApi({
175176
alias: 'treeSelectApi',
176177
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
177-
triggerFn: () =>
178-
cy.selectAccordionItem([
179-
MANAGEIQ_REGION_ACCORDION_ITEM,
180-
SCHEDULES_ACCORDION_ITEM,
181-
]),
178+
triggerFn: () => cy.accordionItem(SCHEDULES_ACCORDION_ITEM),
182179
});
183180
});
184181

@@ -188,146 +185,139 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
188185

189186
/* ===== Selecting any option other than "Automation Tasks" from "Action" dropdown does not hide the Filter dropdown ===== */
190187

191-
cy.get('select#action_typ').select(actionTypeVmAnalysis);
192-
cy.get('select#action_typ').should('have.value', actionTypeVmAnalysis);
193-
// Checking for Filter type dropdown
194-
verifyFilterTypeDropdownExists();
195-
196-
cy.get('select#action_typ').select(actionTypeTemplateAnalysis);
197-
cy.get('select#action_typ').should(
198-
'have.value',
199-
actionTypeTemplateAnalysis
188+
// Selecting "Vm Analysis" to verify filter type dropdown
189+
cy.getFormSelectFieldById('action_typ').select(ACTION_TYPE_VM_ANALYSIS);
190+
cy.getFormLabelByInputId('filter_typ').should('exist');
191+
cy.getFormSelectFieldById('filter_typ').should('exist');
192+
// Selecting "Template Analysis" to verify filter type dropdown
193+
cy.getFormSelectFieldById('action_typ').select(
194+
ACTION_TYPE_TEMPLATE_ANALYSIS
200195
);
201-
// Checking for Filter type dropdown
202-
verifyFilterTypeDropdownExists();
203-
204-
cy.get('select#action_typ').select(actionTypeHostAnalysis);
205-
cy.get('select#action_typ').should('have.value', actionTypeHostAnalysis);
206-
// Checking for Filter type dropdown
207-
verifyFilterTypeDropdownExists();
208-
209-
cy.get('select#action_typ').select(actionTypeContainerAnalysis);
210-
cy.get('select#action_typ').should(
211-
'have.value',
212-
actionTypeContainerAnalysis
196+
cy.getFormLabelByInputId('filter_typ').should('exist');
197+
cy.getFormSelectFieldById('filter_typ').should('exist');
198+
// Selecting "Host Analysis" to verify filter type dropdown
199+
cy.getFormSelectFieldById('action_typ').select(ACTION_TYPE_HOST_ANALYSIS);
200+
cy.getFormLabelByInputId('filter_typ').should('exist');
201+
cy.getFormSelectFieldById('filter_typ').should('exist');
202+
// Selecting "Container Analysis" to verify filter type dropdown
203+
cy.getFormSelectFieldById('action_typ').select(
204+
ACTION_TYPE_CONTAINER_ANALYSIS
213205
);
214-
// Checking for Filter type dropdown
215-
verifyFilterTypeDropdownExists();
216-
217-
cy.get('select#action_typ').select(actionTypeClusterAnalysis);
218-
cy.get('select#action_typ').should('have.value', actionTypeClusterAnalysis);
219-
// Checking for Filter type dropdown
220-
verifyFilterTypeDropdownExists();
221-
222-
cy.get('select#action_typ').select(actionTypeDataStoreAnalysis);
223-
cy.get('select#action_typ').should(
224-
'have.value',
225-
actionTypeDataStoreAnalysis
206+
cy.getFormLabelByInputId('filter_typ').should('exist');
207+
cy.getFormSelectFieldById('filter_typ').should('exist');
208+
// Selecting "Cluster Analysis" to verify filter type dropdown
209+
cy.getFormSelectFieldById('action_typ').select(
210+
ACTION_TYPE_CLUSTER_ANALYSIS
226211
);
227-
// Checking for Filter type dropdown
228-
verifyFilterTypeDropdownExists();
229-
230-
cy.get('select#action_typ').select(actionTypeVmCompilanceCheck);
231-
cy.get('select#action_typ').should(
232-
'have.value',
233-
actionTypeVmCompilanceCheck
212+
cy.getFormLabelByInputId('filter_typ').should('exist');
213+
cy.getFormSelectFieldById('filter_typ').should('exist');
214+
// Selecting "DataStore Analysis" to verify filter type dropdown
215+
cy.getFormSelectFieldById('action_typ').select(
216+
ACTION_TYPE_DATA_STORE_ANALYSIS
234217
);
235-
// Checking for Filter type dropdown
236-
verifyFilterTypeDropdownExists();
237-
238-
cy.get('select#action_typ').select(actionTypeHostCompilanceCheck);
239-
cy.get('select#action_typ').should(
240-
'have.value',
241-
actionTypeHostCompilanceCheck
218+
cy.getFormLabelByInputId('filter_typ').should('exist');
219+
cy.getFormSelectFieldById('filter_typ').should('exist');
220+
// Selecting "Vm Compilance Check" to verify filter type dropdown
221+
cy.getFormSelectFieldById('action_typ').select(
222+
ACTION_TYPE_VM_COMPILANCE_CHECK
242223
);
243-
// Checking for Filter type dropdown
244-
verifyFilterTypeDropdownExists();
245-
246-
cy.get('select#action_typ').select(actionTypeContainerCompilanceCheck);
247-
cy.get('select#action_typ').should(
248-
'have.value',
249-
actionTypeContainerCompilanceCheck
224+
cy.getFormLabelByInputId('filter_typ').should('exist');
225+
cy.getFormSelectFieldById('filter_typ').should('exist');
226+
// Selecting "Host Compilance Check" to verify filter type dropdown
227+
cy.getFormSelectFieldById('action_typ').select(
228+
ACTION_TYPE_HOST_COMPILANCE_CHECK
229+
);
230+
cy.getFormLabelByInputId('filter_typ').should('exist');
231+
cy.getFormSelectFieldById('filter_typ').should('exist');
232+
// Selecting "Container Compilance Check" to verify filter type dropdown
233+
cy.getFormSelectFieldById('action_typ').select(
234+
ACTION_TYPE_CONTAINER_COMPILANCE_CHECK
250235
);
251-
// Checking for Filter type dropdown
252-
verifyFilterTypeDropdownExists();
236+
cy.getFormLabelByInputId('filter_typ').should('exist');
237+
cy.getFormSelectFieldById('filter_typ').should('exist');
253238

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

256-
cy.get('select#action_typ').select(actionTypeAutomationTasks);
257-
cy.get('select#action_typ').should('have.value', actionTypeAutomationTasks);
241+
cy.getFormSelectFieldById('action_typ').select(
242+
ACTION_TYPE_AUTOMATION_TASKS
243+
);
244+
cy.getFormSelectFieldById('action_typ').should(
245+
'have.value',
246+
ACTION_TYPE_AUTOMATION_TASKS
247+
);
258248

259249
// Checking for Zone dropdown
260-
cy.get('label[for="zone_id"]').should('exist');
261-
cy.get('select#zone_id').should('exist');
250+
cy.getFormLabelByInputId('zone_id').should('exist');
251+
cy.getFormSelectFieldById('zone_id').should('exist');
262252

263253
// Checking for Object Details
264254
cy.get('h3[name="object_details"]').should('exist');
265255
// Checking for System/Process dropdown
266-
cy.get('label[for="instance_name"]').should('exist');
267-
cy.get('select#instance_name').should('exist');
256+
cy.getFormLabelByInputId('instance_name').should('exist');
257+
cy.getFormSelectFieldById('instance_name').should('exist');
268258
// Checking for Messsage textfield
269-
cy.get('label[for="message"]').should('exist');
270-
cy.get('input#message').should('exist');
259+
cy.getFormLabelByInputId('message').should('exist');
260+
cy.getFormInputFieldById('message').should('exist');
271261
// Checking for Request textfield
272-
cy.get('label[for="request"]').should('exist');
273-
cy.get('input#request').should('exist');
262+
cy.getFormLabelByInputId('request').should('exist');
263+
cy.getFormInputFieldById('request').should('exist');
274264

275265
// Checking for Object
276266
cy.get('h3[name="object_attributes"]').should('exist');
277267
// Checking for Type Combobox
278-
cy.get('label[for="target_class"]').should('exist');
279-
cy.get('input[role="combobox"]#target_class').should('exist');
268+
cy.getFormLabelByInputId('target_class').should('exist');
269+
cy.getFormInputFieldById('target_class').should('exist');
280270
// Checking for Object Combobox
281-
cy.get('label[for="target_id"]').should('exist');
282-
cy.get('input[role="combobox"]#target_id').should('exist');
271+
cy.getFormLabelByInputId('target_id').should('exist');
272+
cy.getFormInputFieldById('target_id').should('exist');
283273

284274
// Checking for Attribute/Value pairs
285275
cy.contains('h3', 'Attribute/Value Pairs').should('exist');
286276
// Checking for 5 attribute-value pairs text fields
287-
cy.get('input#attribute_1').should('exist');
288-
cy.get('input#value_1').should('exist');
289-
cy.get('input#attribute_2').should('exist');
290-
cy.get('input#value_2').should('exist');
291-
cy.get('input#attribute_3').should('exist');
292-
cy.get('input#value_3').should('exist');
293-
cy.get('input#attribute_4').should('exist');
294-
cy.get('input#value_4').should('exist');
295-
cy.get('input#attribute_5').should('exist');
296-
cy.get('input#value_5').should('exist');
277+
cy.getFormInputFieldById('attribute_1').should('exist');
278+
cy.getFormInputFieldById('value_1').should('exist');
279+
cy.getFormInputFieldById('attribute_2').should('exist');
280+
cy.getFormInputFieldById('value_2').should('exist');
281+
cy.getFormInputFieldById('attribute_3').should('exist');
282+
cy.getFormInputFieldById('value_3').should('exist');
283+
cy.getFormInputFieldById('attribute_4').should('exist');
284+
cy.getFormInputFieldById('value_4').should('exist');
285+
cy.getFormInputFieldById('attribute_5').should('exist');
286+
cy.getFormInputFieldById('value_5').should('exist');
297287

298288
/* ===== Selecting "Once" option from "Run" dropdown does not show the "Every" dropdown ===== */
299-
300-
cy.get('select#timer_typ').select(timerTypeOnce);
289+
cy.getFormSelectFieldById('timer_typ').select(TIMER_TYPE_ONCE);
290+
cy.getFormSelectFieldById('timer_typ').should(
291+
'have.value',
292+
TIMER_TYPE_ONCE
293+
);
301294
// Checking whether the Every dropdown is hidden
302-
cy.get('input#timer_value').should('not.exist');
295+
cy.getFormInputFieldById('timer_value').should('not.exist');
303296

304297
/* ===== Selecting any other option other than "Once" from "Run" dropdown shows the "Every" dropdown ===== */
305-
306-
cy.get('select#timer_typ').select(timerTypeHourly);
307-
// Checking whether the "Every" dropdown exist
308-
verifyTimerDropdownExists();
309-
310-
cy.get('select#timer_typ').select(timerTypeDaily);
311-
// Checking whether the "Every" dropdown exist
312-
verifyTimerDropdownExists();
313-
314-
cy.get('select#timer_typ').select(timerTypeWeekly);
315-
// Checking whether the "Every" dropdown exist
316-
verifyTimerDropdownExists();
317-
318-
cy.get('select#timer_typ').select(timerTypeMonthly);
319-
// Checking whether the "Every" dropdown exist
320-
verifyTimerDropdownExists();
298+
// Selecting "Hourly" to verify timer dropdown
299+
cy.getFormSelectFieldById('timer_typ').select(TIMER_TYPE_HOURLY);
300+
cy.getFormLabelByInputId('timer_value').should('exist');
301+
cy.getFormSelectFieldById('timer_value').should('exist');
302+
// Selecting "Daily" to verify timer dropdown
303+
cy.getFormSelectFieldById('timer_typ').select(TIMER_TYPE_DAILY);
304+
cy.getFormLabelByInputId('timer_value').should('exist');
305+
cy.getFormSelectFieldById('timer_value').should('exist');
306+
// Selecting "Weekly" to verify timer dropdown
307+
cy.getFormSelectFieldById('timer_typ').select(TIMER_TYPE_WEEKLY);
308+
cy.getFormLabelByInputId('timer_value').should('exist');
309+
cy.getFormSelectFieldById('timer_value').should('exist');
310+
// Selecting "Monthly" to verify timer dropdown
311+
cy.getFormSelectFieldById('timer_typ').select(TIMER_TYPE_MONTHLY);
312+
cy.getFormLabelByInputId('timer_value').should('exist');
313+
cy.getFormSelectFieldById('timer_value').should('exist');
321314
});
322315

323316
it('Checking whether Cancel button works on the Add form', () => {
324317
// Open add schedule form
325318
selectConfigMenu(ADD_SCHEDULE_CONFIG_OPTION);
326319
// Cancel the form
327-
cy.contains(
328-
'#main-content .bx--btn-set button[type="button"]',
329-
cancelButton
330-
)
320+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT)
331321
.should('be.enabled')
332322
.click();
333323
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_OPERATION_CANCELED);
@@ -344,10 +334,10 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
344334
// Open edit schedule form
345335
selectConfigMenu(EDIT_SCHEDULE_CONFIG_OPTION);
346336
// Editing name and description
347-
cy.get('input#name').clear().type(editedScheduleName);
348-
cy.get('input#description').clear().type(editedDescription);
337+
cy.getFormInputFieldById('name').clear().type(EDITED_SCHEDULE_NAME);
338+
cy.getFormInputFieldById('description').clear().type(EDITED_DESCRIPTION);
349339
// Confirms Save button is enabled after making edits
350-
cy.contains('#main-content .bx--btn-set button[type="submit"]', saveButton)
340+
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
351341
.should('be.enabled')
352342
.click();
353343
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SCHEDULE_SAVED);
@@ -365,18 +355,25 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
365355
// Open edit schedule form
366356
selectConfigMenu(EDIT_SCHEDULE_CONFIG_OPTION);
367357
// Editing description and start date
368-
cy.get('input#description').clear().type(editedDescription);
369-
cy.get('input#start_date').clear().type(editedStartDate);
370-
cy.contains('#main-content .bx--btn-set button[type="button"]', resetButton)
358+
cy.getFormInputFieldById('description').clear().type(EDITED_DESCRIPTION);
359+
cy.getFormInputFieldById('start_date').clear().type(EDITED_START_DATE);
360+
// Resetting
361+
cy.getFormFooterButtonByType(RESET_BUTTON_TEXT)
371362
.should('be.enabled')
372363
.click();
373364
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_RESET_SCHEDULE);
374365
// Confirming the edited fields contain the old values after resetting
375-
cy.get('input#description').should('have.value', initialDescription);
376-
cy.get('input#start_date').should('have.value', initialStartDate);
366+
cy.getFormInputFieldById('description').should(
367+
'have.value',
368+
INITIAL_DESCRIPTION
369+
);
370+
cy.getFormInputFieldById('start_date').should(
371+
'have.value',
372+
INITIAL_START_DATE
373+
);
377374

378375
/* ===== Checking whether Cancel button works ===== */
379-
cy.contains('#main-content .bx--btn-set button[type="button"]', CANCEL_BUTTON_TEXT)
376+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT)
380377
.should('be.enabled')
381378
.click();
382379
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_OPERATION_CANCELED);

0 commit comments

Comments
 (0)