Skip to content

Commit dacb5da

Browse files
Added automated tests with cypress for Schedule form under Application-Settings
1 parent c9623dd commit dacb5da

File tree

2 files changed

+301
-1
lines changed

2 files changed

+301
-1
lines changed
Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
/* eslint-disable no-undef */
2+
3+
function addSchedule() {
4+
cy.get("#miq_schedule_vmdb_choice").click();
5+
cy.get('ul[aria-label="Configuration"] [title="Add a new Schedule"]').click();
6+
// Checks if Save button is disabled initially
7+
cy.contains(
8+
'#main-content .bx--btn-set button[type="submit"]',
9+
"Save"
10+
).should("be.disabled");
11+
// Adding data
12+
cy.get("input#name").type("Test name");
13+
cy.get("input#description").type("Test description");
14+
cy.get('input[type="checkbox"]#enabled').check({ force: true });
15+
cy.get("select#action_typ").select("VM Analysis");
16+
cy.get("select#filter_typ").select("A single VM");
17+
cy.get("select#timer_typ").select("Hourly");
18+
cy.get("select#timer_value").select("1 Hour");
19+
cy.get('input[role="combobox"]#time_zone').click();
20+
cy.contains('[role="option"]', "(GMT-10:00) Hawaii")
21+
.should("be.visible")
22+
.click();
23+
cy.get("input#start_date").type("06/30/2025", { force: true });
24+
cy.get("input#start_time").type("11:23");
25+
// Checks if Save button is enabled once all required fields are filled
26+
cy.contains('#main-content .bx--btn-set button[type="submit"]', "Save")
27+
.should("be.enabled")
28+
.click();
29+
}
30+
31+
describe("Settings > Application Settings > Settings > Schedules > Configuration > Add a new schedule", () => {
32+
beforeEach(() => {
33+
cy.login();
34+
cy.menu("Settings", "Application Settings");
35+
cy.get('[title="Schedules"]')
36+
.click()
37+
.then(() => {
38+
cy.get("#miq_schedule_vmdb_choice").click();
39+
cy.get(
40+
'ul[aria-label="Configuration"] [title="Add a new Schedule"]'
41+
).click();
42+
});
43+
});
44+
45+
describe("Automate schedule form operations", () => {
46+
it("Validate visibility of elements based on dropdown selections", () => {
47+
/* Selecting any option other than "Automation Tasks" from "Action" dropdown does not hide the Filter dropdown */
48+
49+
cy.get("select#action_typ").select("VM Analysis");
50+
cy.get("select#action_typ").should("have.value", "vm");
51+
// Checking for Filter type dropdown
52+
cy.get('label[for="filter_typ"]').should("exist");
53+
cy.get("select#filter_typ").should("exist");
54+
55+
cy.get("select#action_typ").select("Template Analysis");
56+
cy.get("select#action_typ").should("have.value", "miq_template");
57+
// Checking for Filter type dropdown
58+
cy.get('label[for="filter_typ"]').should("exist");
59+
cy.get("select#filter_typ").should("exist");
60+
61+
cy.get("select#action_typ").select("Host Analysis");
62+
cy.get("select#action_typ").should("have.value", "host");
63+
// Checking for Filter type dropdown
64+
cy.get('label[for="filter_typ"]').should("exist");
65+
cy.get("select#filter_typ").should("exist");
66+
67+
cy.get("select#action_typ").select("Container Image Analysis");
68+
cy.get("select#action_typ").should("have.value", "container_image");
69+
// Checking for Filter type dropdown
70+
cy.get('label[for="filter_typ"]').should("exist");
71+
cy.get("select#filter_typ").should("exist");
72+
73+
cy.get("select#action_typ").select("Cluster Analysis");
74+
cy.get("select#action_typ").should("have.value", "emscluster");
75+
// Checking for Filter type dropdown
76+
cy.get('label[for="filter_typ"]').should("exist");
77+
cy.get("select#filter_typ").should("exist");
78+
79+
cy.get("select#action_typ").select("Datastore Analysis");
80+
cy.get("select#action_typ").should("have.value", "storage");
81+
// Checking for Filter type dropdown
82+
cy.get('label[for="filter_typ"]').should("exist");
83+
cy.get("select#filter_typ").should("exist");
84+
85+
cy.get("select#action_typ").select("VM Compliance Check");
86+
cy.get("select#action_typ").should("have.value", "vm_check_compliance");
87+
// Checking for Filter type dropdown
88+
cy.get('label[for="filter_typ"]').should("exist");
89+
cy.get("select#filter_typ").should("exist");
90+
91+
cy.get("select#action_typ").select("Host Compliance Check");
92+
cy.get("select#action_typ").should("have.value", "host_check_compliance");
93+
// Checking for Filter type dropdown
94+
cy.get('label[for="filter_typ"]').should("exist");
95+
cy.get("select#filter_typ").should("exist");
96+
97+
cy.get("select#action_typ").select("Container Image Compliance Check");
98+
cy.get("select#action_typ").should(
99+
"have.value",
100+
"container_image_check_compliance"
101+
);
102+
// Checking for Filter type dropdown
103+
cy.get('label[for="filter_typ"]').should("exist");
104+
cy.get("select#filter_typ").should("exist");
105+
106+
/* Selecting "Automation Tasks" option from "Action" dropdown shows Zone, Object details & Object fields */
107+
108+
cy.get("select#action_typ").select("Automation Tasks");
109+
cy.get("select#action_typ").should("have.value", "automation_request");
110+
111+
// Checking for Zone dropdown
112+
cy.get('label[for="zone_id"]').should("exist");
113+
cy.get("select#zone_id").should("exist");
114+
115+
// Checking for Object Details
116+
cy.get('h3[name="object_details"]').should("exist");
117+
// Checking for System/Process dropdown
118+
cy.get('label[for="instance_name"]').should("exist");
119+
cy.get("select#instance_name").should("exist");
120+
// Checking for Messsage textfield
121+
cy.get('label[for="message"]').should("exist");
122+
cy.get("input#message").should("exist");
123+
// Checking for Request textfield
124+
cy.get('label[for="request"]').should("exist");
125+
cy.get("input#request").should("exist");
126+
127+
// Checking for Object
128+
cy.get('h3[name="object_attributes"]').should("exist");
129+
// Checking for Type Combobox
130+
cy.get('label[for="target_class"]').should("exist");
131+
cy.get('input[role="combobox"]#target_class').should("exist");
132+
// Checking for Object Combobox
133+
cy.get('label[for="target_id"]').should("exist");
134+
cy.get('input[role="combobox"]#target_id').should("exist");
135+
136+
// Checking for Attribute/Value pairs
137+
cy.contains("h3", "Attribute/Value Pairs").should("exist");
138+
// Checking for 5 attribute-value pairs text fields
139+
cy.get("input#attribute_1").should("exist");
140+
cy.get("input#value_1").should("exist");
141+
cy.get("input#attribute_2").should("exist");
142+
cy.get("input#value_2").should("exist");
143+
cy.get("input#attribute_3").should("exist");
144+
cy.get("input#value_3").should("exist");
145+
cy.get("input#attribute_4").should("exist");
146+
cy.get("input#value_4").should("exist");
147+
cy.get("input#attribute_5").should("exist");
148+
cy.get("input#value_5").should("exist");
149+
150+
/* Selecting "Once" option from "Run" dropdown does not show the "Every" dropdown */
151+
152+
cy.get("select#timer_typ").select("Once");
153+
// Checking whether the Every dropdown is hidden
154+
cy.get("input#timer_value").should("not.exist");
155+
156+
/* Selecting any other option other than "Once" from "Run" dropdown shows the "Every" dropdown */
157+
158+
cy.get("select#timer_typ").select("Hours", { force: true });
159+
// Checking whether the "Every" dropdown exist
160+
cy.get('label[for="timer_value"]').should("exist");
161+
cy.get("select#timer_value").should("exist");
162+
163+
cy.get("select#timer_typ").select("Days", { force: true });
164+
// Checking whether the "Every" dropdown exist
165+
cy.get('label[for="timer_value"]').should("exist");
166+
cy.get("select#timer_value").should("exist");
167+
168+
cy.get("select#timer_typ").select("Weeks", { force: true });
169+
// Checking whether the "Every" dropdown exist
170+
cy.get('label[for="timer_value"]').should("exist");
171+
cy.get("select#timer_value").should("exist");
172+
173+
cy.get("select#timer_typ").select("Months", { force: true });
174+
// Checking whether the "Every" dropdown exist
175+
cy.get('label[for="timer_value"]').should("exist");
176+
cy.get("select#timer_value").should("exist");
177+
});
178+
179+
it("Can add, edit, enable, disable, queue-up and delete a schedule", () => {
180+
/* Checking whether Cancel button works on the add form */
181+
182+
cy.contains('#main-content .bx--btn-set button[type="button"]', "Cancel")
183+
.should("be.enabled")
184+
.click();
185+
cy.get("#main_div #flash_msg_div .alert-success").contains(
186+
"Add was cancelled by the user"
187+
);
188+
189+
/* Checking whether adding a schedule works */
190+
191+
addSchedule();
192+
cy.get("#main_div #flash_msg_div .alert-success").contains(
193+
'Schedule "Test name" was saved'
194+
);
195+
196+
/* Checking whether creating a duplicate record is restricted */
197+
198+
addSchedule();
199+
cy.get("#main_div #flash_msg_div .alert-danger").contains(
200+
"Error when adding a new schedule: Validation failed: MiqSchedule: Name has already been taken"
201+
);
202+
203+
// Selecting the created schedule
204+
cy.contains("li.list-group-item", "Test name").click();
205+
206+
/* Checking whether Cancel button works on the Edit form */
207+
208+
cy.get("#miq_schedule_vmdb_choice").click();
209+
cy.get(
210+
'ul[aria-label="Configuration"] [title="Edit this Schedule"]'
211+
).click();
212+
cy.contains('#main-content .bx--btn-set button[type="button"]', "Cancel")
213+
.should("be.enabled")
214+
.click();
215+
cy.get("#main_div #flash_msg_div .alert-success").contains(
216+
'Edit of "Test name" was cancelled by the user'
217+
);
218+
219+
/* Checking whether Reset button works on the Edit form */
220+
221+
cy.get("#miq_schedule_vmdb_choice").click();
222+
cy.get(
223+
'ul[aria-label="Configuration"] [title="Edit this Schedule"]'
224+
).click();
225+
// Editing description and start date
226+
cy.get("input#description").clear().type("Dummy description");
227+
cy.get("input#start_date").clear().type("07/21/2025", { force: true });
228+
cy.contains('#main-content .bx--btn-set button[type="button"]', "Reset")
229+
.should("be.enabled")
230+
.click();
231+
cy.get("#main_div #flash_msg_div .alert-warning").contains(
232+
"All changes have been reset"
233+
);
234+
// Confirming the edited fields contain the old value
235+
cy.get("input#description").should("have.value", "Test description");
236+
cy.get("input#start_date").should("have.value", "06/30/2025");
237+
238+
/* Checking whether Edit functionality works */
239+
240+
// Editing name and description
241+
cy.get("input#name").clear().type("Dummy name");
242+
cy.get("input#description").clear().type("Dummy description");
243+
// Confirms Save button is enabled after making edits
244+
cy.contains('#main-content .bx--btn-set button[type="submit"]', "Save")
245+
.should("be.enabled")
246+
.click();
247+
cy.get("#main_div #flash_msg_div .alert-success").contains(
248+
'Schedule "Dummy name" was saved'
249+
);
250+
251+
/* Checking whether Disabling the schedule works */
252+
253+
cy.get("#miq_schedule_vmdb_choice").click();
254+
cy.get(
255+
'ul[aria-label="Configuration"] [title="Disable this Schedule"]'
256+
).click();
257+
cy.get("#main_div #flash_msg_div .alert-info").contains(
258+
"The selected Schedules were disabled"
259+
);
260+
261+
/* Checking whether Enabling the schedule works */
262+
263+
cy.get("#miq_schedule_vmdb_choice").click();
264+
cy.get(
265+
'ul[aria-label="Configuration"] [title="Enable this Schedule"]'
266+
).click();
267+
cy.get("#main_div #flash_msg_div .alert-info").contains(
268+
"The selected Schedules were enabled"
269+
);
270+
271+
/* Checking whether Queueing up the schedule to run now */
272+
273+
cy.get("#miq_schedule_vmdb_choice").click();
274+
cy.get(
275+
'ul[aria-label="Configuration"] [title="Queue up this Schedule to run now"]'
276+
).click();
277+
cy.get("#main_div #flash_msg_div .alert-success").contains(
278+
"The selected Schedule has been queued to run"
279+
);
280+
281+
/* Checking whether Deleting the schedule works */
282+
283+
cy.get("#miq_schedule_vmdb_choice").click();
284+
cy.on("window:confirm", (text) => {
285+
expect(text).to.eq(
286+
"Warning: This Schedule and ALL of its components will be permanently removed!"
287+
);
288+
return true;
289+
});
290+
cy.get(
291+
'ul[aria-label="Configuration"] [title="Delete this Schedule from the Database"]'
292+
).click();
293+
cy.get("#main_div #flash_msg_div .alert-success").contains(
294+
'Schedule "Dummy name": Delete successful'
295+
);
296+
});
297+
});
298+
});

cypress/support/e2e.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ import './assertions/expect_text.js'
5959
// Network and aborted errors are exlusive to firefox when cypress navigates to a new page before the api calls for the last page are fullly loaded
6060
Cypress.on('uncaught:exception', (err, runnable) => {
6161
console.log(err.message);
62-
if (err.message.includes(`Cannot read properties of undefined (reading 'received')`) || // Error handler for Chrome
62+
if (err.message.includes(`Cannot read properties of undefined (reading 'received')`) || // Error handler for Chrome
63+
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
6365
err.message.includes('subscription is undefined') || // Error handler for Firefox
6466
err.message.includes('NetworkError when attempting to fetch resource.') || // Error handler for Firefox
6567
err.message.includes('The operation was aborted.')) // Error handler for Firefox

0 commit comments

Comments
 (0)