Skip to content

Commit b94b6eb

Browse files
Added clean up in schedule form tests
1 parent d2c9637 commit b94b6eb

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

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

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function addSchedule() {
2424
cy.contains('[role="option"]', '(GMT-10:00) Hawaii')
2525
.should('be.visible')
2626
.click();
27-
cy.get('input#start_date').type('06/30/2025', { force: true });
27+
cy.get('input#start_date').type('06/30/2025');
2828
cy.get('input#start_time').type('11:23');
2929
// Checks if Save button is enabled once all required fields are filled
3030
cy.contains('#main-content .bx--btn-set button[type="submit"]', 'Save')
@@ -47,11 +47,41 @@ function deleteSchedule(scheduleName = 'Test name') {
4747
);
4848
}
4949

50+
function invokeCleanupDeletion() {
51+
// Iterate and clean up any leftover schedules created during the test
52+
cy.get('li.list-group-item').each(($el) => {
53+
const text = $el?.text()?.trim();
54+
if (text === 'Test name') {
55+
deleteSchedule();
56+
return false;
57+
}
58+
if (text === 'Dummy name') {
59+
deleteSchedule('Dummy name');
60+
return false;
61+
}
62+
return true;
63+
});
64+
}
65+
66+
function verifyFilterTypeDropdownExists() {
67+
cy.get('label[for="filter_typ"]').should('exist');
68+
cy.get('select#filter_typ').should('exist');
69+
}
70+
71+
function verifyTimerDropdownExists() {
72+
cy.get('label[for="timer_value"]').should('exist');
73+
cy.get('select#timer_value').should('exist');
74+
}
75+
5076
describe('Automate Schedule form operations: Settings > Application Settings > Settings > Schedules > Configuration > Add a new schedule', () => {
5177
beforeEach(() => {
5278
cy.login();
53-
cy.menu('Settings', 'Application Settings');
79+
cy.menu(settingsMenuOption, appSettingsMenuOption);
80+
cy.intercept('POST', '/ops/tree_select?id=xx-msc&text=Schedules').as(
81+
'getSchedules'
82+
);
5483
cy.get('[title="Schedules"]').click();
84+
cy.wait('@getSchedules');
5585
});
5686

5787
it('Validate visibility of elements based on dropdown selections', () => {
@@ -168,22 +198,22 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
168198

169199
/* ===== Selecting any other option other than "Once" from "Run" dropdown shows the "Every" dropdown ===== */
170200

171-
cy.get('select#timer_typ').select('Hours', { force: true });
201+
cy.get('select#timer_typ').select('Hours');
172202
// Checking whether the "Every" dropdown exist
173203
cy.get('label[for="timer_value"]').should('exist');
174204
cy.get('select#timer_value').should('exist');
175205

176-
cy.get('select#timer_typ').select('Days', { force: true });
206+
cy.get('select#timer_typ').select('Days');
177207
// Checking whether the "Every" dropdown exist
178208
cy.get('label[for="timer_value"]').should('exist');
179209
cy.get('select#timer_value').should('exist');
180210

181-
cy.get('select#timer_typ').select('Weeks', { force: true });
211+
cy.get('select#timer_typ').select('Weeks');
182212
// Checking whether the "Every" dropdown exist
183213
cy.get('label[for="timer_value"]').should('exist');
184214
cy.get('select#timer_value').should('exist');
185215

186-
cy.get('select#timer_typ').select('Months', { force: true });
216+
cy.get('select#timer_typ').select('Months');
187217
// Checking whether the "Every" dropdown exist
188218
cy.get('label[for="timer_value"]').should('exist');
189219
cy.get('select#timer_value').should('exist');
@@ -221,8 +251,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
221251
'Schedule "Dummy name" was saved'
222252
);
223253

224-
/* ===== Deleting schedule ===== */
225-
deleteSchedule('Dummy name');
254+
/* ===== Delete is already handled from afterEach hook ===== */
226255
});
227256

228257
it('Checking whether Cancel & Reset buttons work fine in the Edit form', () => {
@@ -246,7 +275,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
246275
selectConfigMenu('Edit this Schedule');
247276
// Editing description and start date
248277
cy.get('input#description').clear().type('Dummy description');
249-
cy.get('input#start_date').clear().type('07/21/2025', { force: true });
278+
cy.get('input#start_date').clear().type('07/21/2025');
250279
cy.contains('#main-content .bx--btn-set button[type="button"]', 'Reset')
251280
.should('be.enabled')
252281
.click();
@@ -257,9 +286,8 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
257286
cy.get('input#description').should('have.value', 'Test description');
258287
cy.get('input#start_date').should('have.value', '06/30/2025');
259288

260-
/* ===== Deleting schedule ===== */
289+
// Selecting Schedules menu item to bypass a bug, can be removed once #9505 is merged
261290
cy.get('[title="Schedules"]').click();
262-
deleteSchedule();
263291
});
264292

265293
it('Checking whether creating a duplicate record is restricted', () => {
@@ -271,9 +299,6 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
271299
cy.get('#main_div #flash_msg_div .alert-danger').contains(
272300
'Error when adding a new schedule: Validation failed: MiqSchedule: Name has already been taken'
273301
);
274-
275-
/* ===== Deleting schedule ===== */
276-
deleteSchedule();
277302
});
278303

279304
it('Checking whether Disabling, Enabling & Queueing up the schedule works', () => {
@@ -299,8 +324,18 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
299324
cy.get('#main_div #flash_msg_div .alert-success').contains(
300325
'The selected Schedule has been queued to run'
301326
);
327+
});
302328

303-
/* ===== Deleting schedule ===== */
304-
deleteSchedule();
329+
afterEach(() => {
330+
cy?.url()?.then((url) => {
331+
// Ensures navigation to Settings -> Application-Settings in the UI
332+
if (url?.includes('/ops/explorer')) {
333+
invokeCleanupDeletion();
334+
} else {
335+
// Navigate to Settings -> Application-Settings before looking out for Schedules created during test
336+
cy.menu('Settings', 'Application Settings');
337+
invokeCleanupDeletion();
338+
}
339+
});
305340
});
306341
});

cypress/support/e2e.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Cypress.on('uncaught:exception', (err, runnable) => {
6161
console.log(err.message);
6262
if (err.message.includes(`Cannot read properties of undefined (reading 'received')`) || // Error handler for Chrome
6363
err.message.includes(`Cannot read properties of undefined (reading '0')`) || // Error handler for Chrome
64-
err.message.includes('response.filtered_item_list[0] is undefined') || // Error handler for Firefox
6564
err.message.includes('subscription is undefined') || // Error handler for Firefox
6665
err.message.includes('NetworkError when attempting to fetch resource.') || // Error handler for Firefox
6766
err.message.includes('The operation was aborted.')) // Error handler for Firefox

0 commit comments

Comments
 (0)