@@ -36,13 +36,6 @@ const textConstants = {
36
36
ipInputFieldId : 'settings\\.proxy_server_ip' ,
37
37
maxScanSelectFieldId : 'settings\\.concurrent_vm_scans' ,
38
38
39
- // Common selectors
40
- inputFieldLabelSelector : ( forValue ) =>
41
- `#main-content .bx--form label[for="${ forValue } "]` ,
42
- inputFieldSelector : ( inputId ) => `#main-content .bx--form input#${ inputId } ` ,
43
- selectFieldSelector : ( selectId ) => `#main-content .bx--form select#${ selectId } ` ,
44
- buttonSelector : ( type ) => `#main-content .bx--btn-set button[type="${ type } "]` ,
45
-
46
39
// Buttons
47
40
saveButton : 'Save' ,
48
41
cancelButton : 'Cancel' ,
@@ -51,7 +44,6 @@ const textConstants = {
51
44
52
45
// Button types
53
46
submitButtonType : 'submit' ,
54
- normalButtonType : 'button' ,
55
47
56
48
// Flash message types
57
49
flashTypeSuccess : 'success' ,
@@ -74,10 +66,6 @@ const {
74
66
addZoneConfigOption,
75
67
editZoneConfigOption,
76
68
deleteZoneConfigOption,
77
- selectFieldSelector,
78
- buttonSelector,
79
- inputFieldSelector,
80
- inputFieldLabelSelector,
81
69
cancelButton,
82
70
addButton,
83
71
saveButton,
@@ -89,7 +77,6 @@ const {
89
77
flashMessageOperationReset,
90
78
flashMessageZoneUpdated,
91
79
submitButtonType,
92
- normalButtonType,
93
80
formHeaderFragment,
94
81
infoSubHeader,
95
82
settingsSubHeader,
@@ -110,14 +97,14 @@ function addZone() {
110
97
// Open add form
111
98
cy . toolbar ( configToolbarButton , addZoneConfigOption ) ;
112
99
// Adding name, description, ip and scan limit
113
- cy . get ( inputFieldSelector ( nameInputFieldId ) ) . type ( zoneName ) ;
114
- cy . get ( inputFieldSelector ( descriptionInputFieldId ) ) . type (
100
+ cy . getFormInputFieldById ( nameInputFieldId ) . type ( zoneName ) ;
101
+ cy . getFormInputFieldById ( descriptionInputFieldId ) . type (
115
102
initialZoneDescription
116
103
) ;
117
- cy . get ( inputFieldSelector ( ipInputFieldId ) ) . type ( initialServerIp ) ;
118
- cy . get ( selectFieldSelector ( maxScanSelectFieldId ) ) . select ( initialMaxScanLimit ) ;
104
+ cy . getFormInputFieldById ( ipInputFieldId ) . type ( initialServerIp ) ;
105
+ cy . getFormSelectFieldById ( maxScanSelectFieldId ) . select ( initialMaxScanLimit ) ;
119
106
cy . intercept ( 'POST' , '/api/zones' ) . as ( 'createZone' ) ;
120
- cy . contains ( buttonSelector ( submitButtonType ) , addButton )
107
+ cy . getFormFooterButtonByType ( addButton , submitButtonType )
121
108
. should ( 'be.enabled' )
122
109
. click ( ) ;
123
110
cy . wait ( '@createZone' ) ;
@@ -129,9 +116,9 @@ function validateFormElements(isEditForm = false) {
129
116
// Assert Info sub header is visible
130
117
cy . get ( '#main-content .bx--form h3' ) . contains ( infoSubHeader ) ;
131
118
// Assert name field label is visible
132
- cy . get ( inputFieldLabelSelector ( nameInputFieldId ) ) . should ( 'be.visible' ) ;
119
+ cy . getFormLabelByInputId ( nameInputFieldId ) . should ( 'be.visible' ) ;
133
120
// Assert name field is visible and enabled
134
- cy . get ( inputFieldSelector ( nameInputFieldId ) )
121
+ cy . getFormInputFieldById ( nameInputFieldId )
135
122
. should ( 'be.visible' )
136
123
. then ( ( nameField ) => {
137
124
if ( isEditForm ) {
@@ -141,39 +128,39 @@ function validateFormElements(isEditForm = false) {
141
128
}
142
129
} ) ;
143
130
// Assert description field label is visible
144
- cy . get ( inputFieldLabelSelector ( descriptionInputFieldId ) ) . should ( 'be.visible' ) ;
131
+ cy . getFormLabelByInputId ( descriptionInputFieldId ) . should ( 'be.visible' ) ;
145
132
// Assert description field is visible and enabled
146
- cy . get ( inputFieldSelector ( descriptionInputFieldId ) )
133
+ cy . getFormInputFieldById ( descriptionInputFieldId )
147
134
. should ( 'be.visible' )
148
135
. and ( 'be.enabled' ) ;
149
136
// Assert IP field label is visible
150
- cy . get ( inputFieldLabelSelector ( ipInputFieldId ) ) . should ( 'be.visible' ) ;
137
+ cy . getFormLabelByInputId ( ipInputFieldId ) . should ( 'be.visible' ) ;
151
138
// Assert IP field is visible and enabled
152
- cy . get ( inputFieldSelector ( ipInputFieldId ) )
139
+ cy . getFormInputFieldById ( ipInputFieldId )
153
140
. should ( 'be.visible' )
154
141
. and ( 'be.enabled' ) ;
155
142
// Assert Settings sub header is visible
156
143
cy . get ( '#main-content .bx--form h3' ) . contains ( settingsSubHeader ) ;
157
144
// Assert max scan field label is visible
158
- cy . get ( inputFieldLabelSelector ( maxScanSelectFieldId ) ) . should ( 'be.visible' ) ;
145
+ cy . getFormLabelByInputId ( maxScanSelectFieldId ) . should ( 'be.visible' ) ;
159
146
// Assert max scan field is visible and enabled
160
- cy . get ( selectFieldSelector ( maxScanSelectFieldId ) )
147
+ cy . getFormSelectFieldById ( maxScanSelectFieldId )
161
148
. should ( 'be.visible' )
162
149
. and ( 'be.enabled' ) ;
163
150
// Assert cancel button is visible and enabled
164
- cy . contains ( buttonSelector ( normalButtonType ) , cancelButton )
151
+ cy . getFormFooterButtonByType ( cancelButton )
165
152
. should ( 'be.visible' )
166
153
. and ( 'be.enabled' ) ;
167
154
if ( isEditForm ) {
168
155
// Assert reset button is visible and disabled
169
- cy . contains ( buttonSelector ( normalButtonType ) , resetButton )
156
+ cy . getFormFooterButtonByType ( resetButton )
170
157
. should ( 'be.visible' )
171
158
. and ( 'be.disabled' ) ;
172
159
}
173
160
// Assert add/save button is visible and disabled
174
- cy . contains (
175
- buttonSelector ( submitButtonType ) ,
176
- isEditForm ? saveButton : addButton
161
+ cy . getFormFooterButtonByType (
162
+ isEditForm ? saveButton : addButton ,
163
+ submitButtonType
177
164
)
178
165
. should ( 'be.visible' )
179
166
. and ( 'be.disabled' ) ;
@@ -225,7 +212,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
225
212
// Open add form
226
213
cy . toolbar ( configToolbarButton , addZoneConfigOption ) ;
227
214
// Cancelling the form
228
- cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
215
+ cy . getFormFooterButtonByType ( cancelButton ) . click ( ) ;
229
216
cy . expect_flash ( flashTypeWarning , flashMessageOperationCanceled ) ;
230
217
} ) ;
231
218
@@ -245,14 +232,12 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
245
232
// Open edit form
246
233
cy . toolbar ( configToolbarButton , editZoneConfigOption ) ;
247
234
// Update IP & scan limit
248
- cy . get ( inputFieldSelector ( descriptionInputFieldId ) )
235
+ cy . getFormInputFieldById ( descriptionInputFieldId )
249
236
. clear ( )
250
237
. type ( updatedServerIp ) ;
251
- cy . get ( selectFieldSelector ( maxScanSelectFieldId ) ) . select (
252
- updatedMaxScanLimit
253
- ) ;
238
+ cy . getFormSelectFieldById ( maxScanSelectFieldId ) . select ( updatedMaxScanLimit ) ;
254
239
// Save the form
255
- cy . contains ( buttonSelector ( submitButtonType ) , saveButton )
240
+ cy . getFormFooterButtonByType ( saveButton , submitButtonType )
256
241
. should ( 'be.enabled' )
257
242
. click ( ) ;
258
243
cy . expect_flash ( flashTypeSuccess , flashMessageZoneUpdated ) ;
@@ -281,7 +266,7 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
281
266
// Validate fields
282
267
validateFormElements ( true ) ;
283
268
// Cancelling the form
284
- cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
269
+ cy . getFormFooterButtonByType ( cancelButton ) . click ( ) ;
285
270
} ) ;
286
271
287
272
it ( 'Checking whether cancel & reset buttons work on the edit form' , ( ) => {
@@ -298,27 +283,25 @@ describe('Automate Schedule form operations: Settings > Application Settings > S
298
283
cy . toolbar ( configToolbarButton , editZoneConfigOption ) ;
299
284
/* ===== Reset ===== */
300
285
// Update description & IP
301
- cy . get ( inputFieldSelector ( descriptionInputFieldId ) )
286
+ cy . getFormInputFieldById ( descriptionInputFieldId )
302
287
. clear ( )
303
288
. type ( updatedZoneDescription ) ;
304
- cy . get ( inputFieldSelector ( ipInputFieldId ) ) . clear ( ) . type ( updatedServerIp ) ;
289
+ cy . getFormInputFieldById ( ipInputFieldId ) . clear ( ) . type ( updatedServerIp ) ;
305
290
// Resetting the form
306
- cy . contains ( buttonSelector ( normalButtonType ) , resetButton )
307
- . should ( 'be.enabled' )
308
- . click ( ) ;
291
+ cy . getFormFooterButtonByType ( resetButton ) . should ( 'be.enabled' ) . click ( ) ;
309
292
cy . expect_flash ( flashTypeWarning , flashMessageOperationReset ) ;
310
293
// Confirming the edited fields contain the old values after resetting
311
- cy . get ( inputFieldSelector ( descriptionInputFieldId ) ) . should (
294
+ cy . getFormInputFieldById ( descriptionInputFieldId ) . should (
312
295
'have.value' ,
313
296
initialZoneDescription
314
297
) ;
315
- cy . get ( inputFieldSelector ( ipInputFieldId ) ) . should (
298
+ cy . getFormInputFieldById ( ipInputFieldId ) . should (
316
299
'have.value' ,
317
300
initialServerIp
318
301
) ;
319
302
/* ===== Cancel ===== */
320
303
// Cancelling the form
321
- cy . contains ( buttonSelector ( normalButtonType ) , cancelButton ) . click ( ) ;
304
+ cy . getFormFooterButtonByType ( cancelButton ) . click ( ) ;
322
305
cy . expect_flash ( flashTypeWarning , flashMessageOperationCanceled ) ;
323
306
} ) ;
324
307
0 commit comments