webship-js 1.0.45 → 1.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +0 -0
- package/examples/about-us.html +0 -0
- package/examples/ajax-wait-examples.html +147 -0
- package/examples/contact-us.html +0 -0
- package/examples/dynamic-examples.html +499 -0
- package/examples/example-api.json +0 -0
- package/examples/existing-page.html +0 -0
- package/examples/index.html +1 -0
- package/examples/test--then--i-should--see-text-in-element.html +0 -0
- package/examples/test--then--i-should--see-text-matching-pattern.html +0 -0
- package/examples/test--then--i-should-see-text-in-table-row.html +0 -0
- package/examples/test--then--the-checkbox-checked.html +0 -0
- package/examples/test--then--the-element-should_not-contain-cssproperty.html +0 -0
- package/examples/test--then--the-link-should-contain.html +0 -0
- package/examples/test--when--i-attach-file-to-feild.html +0 -0
- package/examples/test--when--i-check-uncheck-checkbox.html +0 -0
- package/examples/test--when--i-click-link.html +0 -0
- package/examples/test--when--i-click-text-in-table-row.html +0 -0
- package/examples/test--when--i-press-button.html +0 -0
- package/examples/test--when--i-reload-page.html +0 -0
- package/examples/test--when--i-scroll-functionality.html +0 -0
- package/examples/test--when--i-scroll-left-right-functionality.html +0 -0
- package/examples/test--when--i-select-option-from-dropdownlist.html +0 -0
- package/examples/test--when--i-select-radio-button.html +95 -0
- package/examples/test--when-i-wait-max-of-time.html +0 -0
- package/examples/test--when-i-wait-page-until-is-loaded.html +0 -0
- package/examples/test--when-i-wait-specific-time.html +0 -0
- package/examples/test-acceptable-url-path.html +0 -0
- package/nightwatch.conf.js +1 -1
- package/package.json +1 -1
- package/tests/features/ajax-wait-examples.feature +24 -0
- package/tests/features/api-step-definitions-individual.feature +0 -0
- package/tests/features/complete-api-testing-examples.feature +0 -0
- package/tests/features/dynamic-content-examples.feature +156 -0
- package/tests/features/modal-advanced-example.feature +54 -0
- package/tests/features/modal-basic-example.feature +42 -0
- package/tests/features/modal-error-handling-example.feature +37 -0
- package/tests/features/test--given--i-am-on-homepage.feature +0 -0
- package/tests/features/test--then--i-should--not--see-text-in-element.feature +0 -0
- package/tests/features/test--then--i-should--see-text-in-element-by-attr.feature +0 -0
- package/tests/features/test--then--i-should--see-text-in-element.feature +0 -0
- package/tests/features/test--then--i-should--see-text-matching-pattern-in-element.feature +0 -0
- package/tests/features/test--then--i-should--see-text-matching-pattern.feature +0 -0
- package/tests/features/test--then--i-should-be-on-page.feature +0 -0
- package/tests/features/test--then--i-should-be-on-the-homepage.feature +0 -0
- package/tests/features/test--then--i-should-not-see-an-element-by-attr.feature +0 -0
- package/tests/features/test--then--i-should-not-see-an-element.feature +0 -0
- package/tests/features/test--then--i-should-see-an-element-by-attr.feature +0 -0
- package/tests/features/test--then--i-should-see-an-element.feature +0 -0
- package/tests/features/test--then--i-should-see-text-in-table-row.feature +0 -0
- package/tests/features/test--then--the-checkbox-is-checked.feature +0 -0
- package/tests/features/test--then--the-checkbox-should-be-checked.feature +0 -0
- package/tests/features/test--then--the-element-should-contain-cssproperty.feature +0 -0
- package/tests/features/test--then--the-element-should-not-contain-cssproperty.feature +0 -0
- package/tests/features/test--then--the-field-should-contain-value.feature +0 -0
- package/tests/features/test--then--the-response-should-contain.feature +0 -0
- package/tests/features/test--then--the-response-status-code-should-be.feature +0 -0
- package/tests/features/test--then--the-url-should-match.feature +0 -0
- package/tests/features/test--then-the-link-should-contain-by-attribute.feature +0 -0
- package/tests/features/test--then-the-link-should-contain.feature +0 -0
- package/tests/features/test--when--i-attach-file-to-feild.feature +0 -0
- package/tests/features/test--when--i-check-checkbox.feature +0 -0
- package/tests/features/test--when--i-click-link-by-attribute.feature +0 -0
- package/tests/features/test--when--i-click-link.feature +0 -0
- package/tests/features/test--when--i-click-text-in-table-row.feature +0 -0
- package/tests/features/test--when--i-fill-in-by-attr.feature +0 -0
- package/tests/features/test--when--i-fill-in-table-by-attr.feature +0 -0
- package/tests/features/test--when--i-fill-in.feature +0 -0
- package/tests/features/test--when--i-go-to-homepage.feature +0 -0
- package/tests/features/test--when--i-move-forward-backward-one-page.feature +0 -0
- package/tests/features/test--when--i-press-button-by-attribute.feature +0 -0
- package/tests/features/test--when--i-press-button.feature +0 -0
- package/tests/features/test--when--i-reload-page.feature +0 -0
- package/tests/features/test--when--i-scroll-left-right.feature +0 -0
- package/tests/features/test--when--i-scroll.feature +0 -0
- package/tests/features/test--when--i-select-option-from-dropdownlist.feature +0 -0
- package/tests/features/test--when--i-select-radio-button.feature +37 -0
- package/tests/features/test--when--i-wait-page-is-loaded.feature +0 -0
- package/tests/features/test--when--i-wait-time.feature +0 -0
- package/tests/step-definitions/webship.js +1469 -503
|
@@ -48,8 +48,8 @@ AfterStep(function () {
|
|
|
48
48
|
* Example #6: Given on homepage
|
|
49
49
|
* Example #7: Given we are on the frontpage
|
|
50
50
|
* Example #8: Given on frontpage
|
|
51
|
-
*
|
|
52
|
-
*
|
|
51
|
+
*
|
|
52
|
+
*
|
|
53
53
|
*/
|
|
54
54
|
Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
|
|
55
55
|
browser.url(browser.launch_url);
|
|
@@ -57,7 +57,13 @@ Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, function (pronounCase,
|
|
|
57
57
|
if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
|
|
58
58
|
defaultTime = browser.globals.minimum_wait_time.page;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
browser.waitForElementPresent('body', defaultTime);
|
|
61
|
+
// Wait for any dynamic content to be loaded
|
|
62
|
+
return browser.executeScript('return document.readyState').then(function(result) {
|
|
63
|
+
if (result !== 'complete') {
|
|
64
|
+
return browser.pause(500);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
61
67
|
});
|
|
62
68
|
|
|
63
69
|
/**
|
|
@@ -73,11 +79,30 @@ Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, function (pronounCase,
|
|
|
73
79
|
*/
|
|
74
80
|
Given(/^(I am |we are )*on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
|
|
75
81
|
browser.url(browser.launch_url + url);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
|
|
83
|
+
// Wait for body element to be present using active DOM polling
|
|
84
|
+
return browser.executeAsync(function(done) {
|
|
85
|
+
var maxAttempts = 20;
|
|
86
|
+
var attempts = 0;
|
|
87
|
+
|
|
88
|
+
var checkBody = setInterval(function() {
|
|
89
|
+
var body = document.querySelector('body');
|
|
90
|
+
var readyState = document.readyState;
|
|
91
|
+
attempts++;
|
|
92
|
+
|
|
93
|
+
if (body && (readyState === 'interactive' || readyState === 'complete')) {
|
|
94
|
+
clearInterval(checkBody);
|
|
95
|
+
done({ found: true });
|
|
96
|
+
} else if (attempts >= maxAttempts) {
|
|
97
|
+
clearInterval(checkBody);
|
|
98
|
+
done({ found: false });
|
|
99
|
+
}
|
|
100
|
+
}, 500);
|
|
101
|
+
}, [], function(result) {
|
|
102
|
+
if (!result || !result.value || !result.value.found) {
|
|
103
|
+
browser.assert.fail('Page body element was not found after navigation to "' + url + '"');
|
|
104
|
+
}
|
|
105
|
+
});
|
|
81
106
|
});
|
|
82
107
|
|
|
83
108
|
/**
|
|
@@ -99,7 +124,13 @@ When(/^(I go |I navigate |we go |we navigate |navigating )?to( the)* (homepage|f
|
|
|
99
124
|
if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
|
|
100
125
|
defaultTime = browser.globals.minimum_wait_time.page;
|
|
101
126
|
}
|
|
102
|
-
|
|
127
|
+
browser.waitForElementPresent('body', defaultTime);
|
|
128
|
+
// Wait for any dynamic content to be loaded
|
|
129
|
+
return browser.executeScript('return document.readyState').then(function(result) {
|
|
130
|
+
if (result !== 'complete') {
|
|
131
|
+
return browser.pause(500);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
103
134
|
});
|
|
104
135
|
|
|
105
136
|
/**
|
|
@@ -119,7 +150,13 @@ When(/^(I go |I navigate |we go |we navigate |navigating )?to "([^"]*)?"$/, func
|
|
|
119
150
|
if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
|
|
120
151
|
defaultTime = browser.globals.minimum_wait_time.page;
|
|
121
152
|
}
|
|
122
|
-
|
|
153
|
+
browser.waitForElementPresent('body', defaultTime);
|
|
154
|
+
// Wait for any dynamic content to be loaded
|
|
155
|
+
return browser.executeScript('return document.readyState').then(function(result) {
|
|
156
|
+
if (result !== 'complete') {
|
|
157
|
+
return browser.pause(500);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
123
160
|
});
|
|
124
161
|
|
|
125
162
|
/**
|
|
@@ -127,24 +164,17 @@ When(/^(I go |I navigate |we go |we navigate |navigating )?to "([^"]*)?"$/, func
|
|
|
127
164
|
*
|
|
128
165
|
* Example #1: Then I should see "Welcome"
|
|
129
166
|
* Example #2: Then we should see "Your accounts for the group is public"
|
|
130
|
-
*
|
|
131
|
-
|
|
132
|
-
Then(/^(I |we )*should see "([^"]*)?"$/, function (pronounCase, expectedText) {
|
|
133
|
-
return this.shouldSee = function (browser) {
|
|
134
|
-
browser.assert.textContains("html", expectedText);
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Asserting a text in the page.
|
|
167
|
+
* Example #3: Then I should not see "Access denied"
|
|
168
|
+
* Example #4: Then we should not see "Edit layout"
|
|
140
169
|
*
|
|
141
|
-
* Example #1: Then I should not see "Access denied"
|
|
142
|
-
* Example #2: Then we should not see "Edit layout"
|
|
143
|
-
*
|
|
144
170
|
*/
|
|
145
|
-
Then(/^(I |we )*should not see "([^"]*)?"$/, function (pronounCase, expectedText) {
|
|
171
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?"$/, function (pronounCase, notCase, expectedText) {
|
|
146
172
|
return this.shouldSee = function (browser) {
|
|
147
|
-
|
|
173
|
+
if (notCase) {
|
|
174
|
+
browser.assert.not.textContains("html", expectedText);
|
|
175
|
+
} else {
|
|
176
|
+
browser.assert.textContains("html", expectedText);
|
|
177
|
+
}
|
|
148
178
|
};
|
|
149
179
|
});
|
|
150
180
|
|
|
@@ -177,7 +207,40 @@ When(/^(I |we )*move backward one page$/, function (pronounCase) {
|
|
|
177
207
|
*
|
|
178
208
|
*/
|
|
179
209
|
When(/^(I |we )*press( the)* "([^"]*)?"( button)*$/, function (pronounCase, theCase, element, buttonCase) {
|
|
180
|
-
|
|
210
|
+
// Actively wait for dynamically generated button by polling the DOM
|
|
211
|
+
return browser.executeAsync(function(buttonText, done) {
|
|
212
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
213
|
+
var attempts = 0;
|
|
214
|
+
|
|
215
|
+
var checkButton = setInterval(function() {
|
|
216
|
+
const buttons = document.querySelectorAll('button, input[type="button"], input[type="submit"], [role="button"], .btn, a');
|
|
217
|
+
var foundButton = null;
|
|
218
|
+
|
|
219
|
+
for (let btn of buttons) {
|
|
220
|
+
const text = (btn.textContent || btn.innerText || btn.value || '').trim();
|
|
221
|
+
if (text === buttonText) {
|
|
222
|
+
foundButton = btn;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
attempts++;
|
|
228
|
+
|
|
229
|
+
if (foundButton) {
|
|
230
|
+
clearInterval(checkButton);
|
|
231
|
+
// Click the button directly
|
|
232
|
+
foundButton.click();
|
|
233
|
+
done({ found: true });
|
|
234
|
+
} else if (attempts >= maxAttempts) {
|
|
235
|
+
clearInterval(checkButton);
|
|
236
|
+
done({ found: false });
|
|
237
|
+
}
|
|
238
|
+
}, 500);
|
|
239
|
+
}, [element], function(result) {
|
|
240
|
+
if (!result || !result.value || !result.value.found) {
|
|
241
|
+
browser.assert.fail('Button "' + element + '" was not found in dynamically generated content');
|
|
242
|
+
}
|
|
243
|
+
});
|
|
181
244
|
});
|
|
182
245
|
|
|
183
246
|
/**
|
|
@@ -208,7 +271,29 @@ When(/^(I |we )*press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, fun
|
|
|
208
271
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
209
272
|
}
|
|
210
273
|
|
|
211
|
-
|
|
274
|
+
// Actively wait for dynamically generated element by polling the DOM
|
|
275
|
+
return browser.executeAsync(function(sel, done) {
|
|
276
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
277
|
+
var attempts = 0;
|
|
278
|
+
|
|
279
|
+
var checkElement = setInterval(function() {
|
|
280
|
+
var element = document.querySelector(sel);
|
|
281
|
+
attempts++;
|
|
282
|
+
|
|
283
|
+
if (element) {
|
|
284
|
+
clearInterval(checkElement);
|
|
285
|
+
element.click();
|
|
286
|
+
done({ found: true });
|
|
287
|
+
} else if (attempts >= maxAttempts) {
|
|
288
|
+
clearInterval(checkElement);
|
|
289
|
+
done({ found: false });
|
|
290
|
+
}
|
|
291
|
+
}, 500);
|
|
292
|
+
}, [selector], function(result) {
|
|
293
|
+
if (!result || !result.value || !result.value.found) {
|
|
294
|
+
browser.assert.fail('Element "' + selector + '" was not found in dynamically generated content');
|
|
295
|
+
}
|
|
296
|
+
});
|
|
212
297
|
});
|
|
213
298
|
|
|
214
299
|
/**
|
|
@@ -219,7 +304,39 @@ When(/^(I |we )*press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, fun
|
|
|
219
304
|
*
|
|
220
305
|
*/
|
|
221
306
|
When(/^(I |we )*click "([^"]*)?"$/, function (pronounCase, item) {
|
|
222
|
-
|
|
307
|
+
// Actively wait for dynamically generated link/button by polling the DOM
|
|
308
|
+
return browser.executeAsync(function(linkText, done) {
|
|
309
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
310
|
+
var attempts = 0;
|
|
311
|
+
|
|
312
|
+
var checkLink = setInterval(function() {
|
|
313
|
+
var clickableElements = document.querySelectorAll('a, button, [role="button"], .btn, input[type="button"], input[type="submit"]');
|
|
314
|
+
var foundElement = null;
|
|
315
|
+
|
|
316
|
+
for (var i = 0; i < clickableElements.length; i++) {
|
|
317
|
+
var text = (clickableElements[i].textContent || clickableElements[i].innerText || clickableElements[i].value || '').trim();
|
|
318
|
+
if (text === linkText) {
|
|
319
|
+
foundElement = clickableElements[i];
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
attempts++;
|
|
325
|
+
|
|
326
|
+
if (foundElement) {
|
|
327
|
+
clearInterval(checkLink);
|
|
328
|
+
foundElement.click();
|
|
329
|
+
done({ found: true });
|
|
330
|
+
} else if (attempts >= maxAttempts) {
|
|
331
|
+
clearInterval(checkLink);
|
|
332
|
+
done({ found: false });
|
|
333
|
+
}
|
|
334
|
+
}, 500);
|
|
335
|
+
}, [item], function(result) {
|
|
336
|
+
if (!result || !result.value || !result.value.found) {
|
|
337
|
+
browser.assert.fail('Link/Button "' + item + '" was not found in dynamically generated content');
|
|
338
|
+
}
|
|
339
|
+
});
|
|
223
340
|
});
|
|
224
341
|
|
|
225
342
|
/**
|
|
@@ -249,7 +366,28 @@ When(/^(I |we )*click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, fun
|
|
|
249
366
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
250
367
|
}
|
|
251
368
|
|
|
252
|
-
return browser.
|
|
369
|
+
return browser.executeAsync(function(sel, done) {
|
|
370
|
+
var maxAttempts = 20;
|
|
371
|
+
var attempts = 0;
|
|
372
|
+
|
|
373
|
+
var checkElement = setInterval(function() {
|
|
374
|
+
var element = document.querySelector(sel);
|
|
375
|
+
attempts++;
|
|
376
|
+
|
|
377
|
+
if (element) {
|
|
378
|
+
clearInterval(checkElement);
|
|
379
|
+
element.click();
|
|
380
|
+
done({ found: true });
|
|
381
|
+
} else if (attempts >= maxAttempts) {
|
|
382
|
+
clearInterval(checkElement);
|
|
383
|
+
done({ found: false });
|
|
384
|
+
}
|
|
385
|
+
}, 500);
|
|
386
|
+
}, [selector], function(result) {
|
|
387
|
+
if (!result || !result.value || !result.value.found) {
|
|
388
|
+
browser.assert.fail('Element with selector "' + selector + '" was not found in dynamically generated content');
|
|
389
|
+
}
|
|
390
|
+
});
|
|
253
391
|
|
|
254
392
|
});
|
|
255
393
|
|
|
@@ -258,110 +396,131 @@ When(/^(I |we )*click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, fun
|
|
|
258
396
|
* This step finds a table, locates a row containing the identifier text, then clicks on the target text within that row.
|
|
259
397
|
*
|
|
260
398
|
* Example #1: When I click "Edit" in the "John Smith" row
|
|
261
|
-
* Example #2: When I click "Delete" in the "Product A" row
|
|
399
|
+
* Example #2: When I click "Delete" in the "Product A" row
|
|
262
400
|
* Example #3: When we click "View Details" in the "Order #12345" row
|
|
263
401
|
* Example #4: And I click "Download" in the "Report 2024" row
|
|
264
402
|
*
|
|
265
403
|
*/
|
|
266
404
|
When(/^(I |we )*click "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, clickText, theCase, rowIdentifier) {
|
|
267
|
-
|
|
268
|
-
return browser.execute(function(rowId, targetText) {
|
|
269
|
-
// Find all tables on the page
|
|
270
|
-
const tables = document.querySelectorAll('table');
|
|
271
|
-
if (tables.length === 0) {
|
|
272
|
-
throw new Error('No tables found on the page');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Search through each table for the row containing the identifier
|
|
276
|
-
for (let table of tables) {
|
|
277
|
-
const rows = table.querySelectorAll('tr');
|
|
278
|
-
for (let row of rows) {
|
|
279
|
-
const rowText = row.textContent || row.innerText;
|
|
280
|
-
if (rowText.includes(rowId)) {
|
|
281
|
-
// Found the correct row, now look for clickable elements with the target text
|
|
282
|
-
|
|
283
|
-
// First, try to find exact text matches in clickable elements
|
|
284
|
-
const clickableElements = row.querySelectorAll('a, button, [onclick], [role="button"], .btn, input[type="submit"], input[type="button"]');
|
|
285
|
-
for (let element of clickableElements) {
|
|
286
|
-
const elementText = (element.textContent || element.innerText || element.value || '').trim();
|
|
287
|
-
if (elementText === targetText) {
|
|
288
|
-
element.click();
|
|
289
|
-
return { success: true, element: element.tagName };
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
405
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
406
|
+
return browser.executeAsync(function(rowId, targetText, done) {
|
|
407
|
+
var maxAttempts = 20;
|
|
408
|
+
var attempts = 0;
|
|
409
|
+
|
|
410
|
+
var checkTable = setInterval(function() {
|
|
411
|
+
// Find all tables on the page
|
|
412
|
+
const tables = document.querySelectorAll('table');
|
|
413
|
+
attempts++;
|
|
414
|
+
|
|
415
|
+
if (tables.length > 0) {
|
|
416
|
+
clearInterval(checkTable);
|
|
417
|
+
|
|
418
|
+
// Search through each table for the row containing the identifier
|
|
419
|
+
for (let table of tables) {
|
|
420
|
+
const rows = table.querySelectorAll('tr');
|
|
421
|
+
for (let row of rows) {
|
|
422
|
+
const rowText = row.textContent || row.innerText;
|
|
423
|
+
if (rowText.includes(rowId)) {
|
|
424
|
+
// Found the correct row, now look for clickable elements with the target text
|
|
425
|
+
|
|
426
|
+
// First, try to find exact text matches in clickable elements
|
|
427
|
+
const clickableElements = row.querySelectorAll('a, button, [onclick], [role="button"], .btn, input[type="submit"], input[type="button"]');
|
|
428
|
+
for (let element of clickableElements) {
|
|
429
|
+
const elementText = (element.textContent || element.innerText || element.value || '').trim();
|
|
430
|
+
if (elementText === targetText) {
|
|
431
|
+
element.click();
|
|
432
|
+
done({ success: true, element: element.tagName });
|
|
433
|
+
return;
|
|
309
434
|
}
|
|
310
|
-
clickableParent = clickableParent.parentElement;
|
|
311
435
|
}
|
|
312
436
|
|
|
313
|
-
// If
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
437
|
+
// If not found in obvious clickable elements, search all elements
|
|
438
|
+
const allElements = row.querySelectorAll('*');
|
|
439
|
+
for (let element of allElements) {
|
|
440
|
+
const elementText = (element.textContent || element.innerText || '').trim();
|
|
441
|
+
if (elementText === targetText) {
|
|
442
|
+
// Check if element or parent is clickable
|
|
443
|
+
let clickableParent = element;
|
|
444
|
+
while (clickableParent && clickableParent !== row) {
|
|
445
|
+
if (clickableParent.tagName === 'A' ||
|
|
446
|
+
clickableParent.tagName === 'BUTTON' ||
|
|
447
|
+
clickableParent.onclick ||
|
|
448
|
+
clickableParent.getAttribute('role') === 'button' ||
|
|
449
|
+
clickableParent.classList.contains('btn') ||
|
|
450
|
+
clickableParent.style.cursor === 'pointer') {
|
|
451
|
+
clickableParent.click();
|
|
452
|
+
done({ success: true, element: clickableParent.tagName });
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
clickableParent = clickableParent.parentElement;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// If no clickable parent found, try clicking the element itself
|
|
459
|
+
try {
|
|
460
|
+
element.click();
|
|
461
|
+
done({ success: true, element: element.tagName });
|
|
462
|
+
return;
|
|
463
|
+
} catch (e) {
|
|
464
|
+
// Continue searching if click failed
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
320
468
|
}
|
|
469
|
+
|
|
470
|
+
// Row found but target text not clickable
|
|
471
|
+
done({
|
|
472
|
+
success: false,
|
|
473
|
+
error: 'Found row containing "' + rowId + '" but could not find clickable "' + targetText + '" within it. Row contains: ' + rowText.substring(0, 200) + '...'
|
|
474
|
+
});
|
|
475
|
+
return;
|
|
321
476
|
}
|
|
322
477
|
}
|
|
323
|
-
|
|
324
|
-
// Row found but target text not clickable
|
|
325
|
-
return {
|
|
326
|
-
success: false,
|
|
327
|
-
error: `Found row containing "${rowId}" but could not find clickable "${targetText}" within it. Row contains: ${rowText.substring(0, 200)}...`
|
|
328
|
-
};
|
|
329
478
|
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// Row not found
|
|
334
|
-
return {
|
|
335
|
-
success: false,
|
|
336
|
-
error: `Could not find row containing "${rowId}". Available rows: ${Array.from(document.querySelectorAll('table tr')).map(r => (r.textContent || '').substring(0, 50)).join(', ')}`
|
|
337
|
-
};
|
|
338
479
|
|
|
480
|
+
// Row not found
|
|
481
|
+
done({
|
|
482
|
+
success: false,
|
|
483
|
+
error: 'Could not find row containing "' + rowId + '". Available rows: ' + Array.from(document.querySelectorAll('table tr')).map(function(r) { return (r.textContent || '').substring(0, 50); }).join(', ')
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
} else if (attempts >= maxAttempts) {
|
|
487
|
+
clearInterval(checkTable);
|
|
488
|
+
done({
|
|
489
|
+
success: false,
|
|
490
|
+
error: 'No tables found on the page after waiting'
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}, 500);
|
|
339
494
|
}, [rowIdentifier, clickText], function(result) {
|
|
340
|
-
if (!result.value.success) {
|
|
341
|
-
|
|
495
|
+
if (!result || !result.value || !result.value.success) {
|
|
496
|
+
var errorMsg = (result && result.value && result.value.error) || 'Could not find "' + clickText + '" in the "' + rowIdentifier + '" row. Please verify the table structure and text content.';
|
|
497
|
+
browser.assert.fail(errorMsg);
|
|
342
498
|
}
|
|
343
499
|
});
|
|
344
500
|
});
|
|
345
501
|
|
|
346
502
|
/**
|
|
347
|
-
* Asserts that specific text is visible within a table row that contains a specified identifier text.
|
|
503
|
+
* Asserts that specific text is visible or not visible within a table row that contains a specified identifier text.
|
|
348
504
|
* This step finds a table, locates a row containing the identifier text, then verifies the target text is visible within that row.
|
|
349
505
|
*
|
|
350
506
|
* Example #1: Then I should see "Active" in the "John Smith" row
|
|
351
|
-
* Example #2: Then I should see "In Stock" in the "Product A" row
|
|
507
|
+
* Example #2: Then I should see "In Stock" in the "Product A" row
|
|
352
508
|
* Example #3: Then we should see "Processing" in the "Order #12345" row
|
|
353
509
|
* Example #4: And I should see "Admin" in the "john.smith@example.com" row
|
|
510
|
+
* Example #5: Then I should not see "Admin" in the "Jane Doe" row
|
|
511
|
+
* Example #6: Then I should not see "Out of Stock" in the "Product A" row
|
|
512
|
+
* Example #7: And I should not see "Inactive" in the "john.smith@example.com" row
|
|
354
513
|
*
|
|
355
514
|
*/
|
|
356
|
-
Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, expectedText, theCase, rowIdentifier) {
|
|
357
|
-
|
|
515
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, notCase, expectedText, theCase, rowIdentifier) {
|
|
516
|
+
|
|
358
517
|
return browser.execute(function(rowId, expectedTxt) {
|
|
359
518
|
// Find all tables
|
|
360
519
|
const tables = document.querySelectorAll('table');
|
|
361
520
|
if (tables.length === 0) {
|
|
362
521
|
throw new Error('No tables found on the page');
|
|
363
522
|
}
|
|
364
|
-
|
|
523
|
+
|
|
365
524
|
// Search through each table for the row containing the identifier
|
|
366
525
|
for (let table of tables) {
|
|
367
526
|
const rows = table.querySelectorAll('tr');
|
|
@@ -377,46 +536,14 @@ Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pron
|
|
|
377
536
|
}
|
|
378
537
|
return false; // Text not found
|
|
379
538
|
}, [rowIdentifier, expectedText], function(result) {
|
|
380
|
-
if (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
* Asserts that specific text is NOT visible within a table row that contains a specified identifier text.
|
|
388
|
-
*
|
|
389
|
-
* Example #1: Then I should not see "Admin" in the "Jane Doe" row
|
|
390
|
-
* Example #2: Then I should not see "Out of Stock" in the "Product A" row
|
|
391
|
-
* Example #3: And I should not see "Inactive" in the "john.smith@example.com" row
|
|
392
|
-
*
|
|
393
|
-
*/
|
|
394
|
-
Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, expectedText, theCase, rowIdentifier) {
|
|
395
|
-
|
|
396
|
-
return browser.execute(function(rowId, expectedTxt) {
|
|
397
|
-
// Find all tables
|
|
398
|
-
const tables = document.querySelectorAll('table');
|
|
399
|
-
if (tables.length === 0) {
|
|
400
|
-
throw new Error('No tables found on the page');
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Search through each table for the row containing the identifier
|
|
404
|
-
for (let table of tables) {
|
|
405
|
-
const rows = table.querySelectorAll('tr');
|
|
406
|
-
for (let row of rows) {
|
|
407
|
-
const rowText = row.textContent || row.innerText;
|
|
408
|
-
if (rowText.includes(rowId)) {
|
|
409
|
-
// Found the correct row, now check if it contains the expected text
|
|
410
|
-
if (rowText.includes(expectedTxt)) {
|
|
411
|
-
return true; // Found the text (this is bad for "should not see")
|
|
412
|
-
}
|
|
413
|
-
}
|
|
539
|
+
if (notCase) {
|
|
540
|
+
if (result.value) {
|
|
541
|
+
throw new Error(`Found "${expectedText}" in the "${rowIdentifier}" row, but it should not be there.`);
|
|
542
|
+
}
|
|
543
|
+
} else {
|
|
544
|
+
if (!result.value) {
|
|
545
|
+
throw new Error(`Could not find "${expectedText}" in the "${rowIdentifier}" row. Please verify the table structure and text content.`);
|
|
414
546
|
}
|
|
415
|
-
}
|
|
416
|
-
return false; // Text not found (this is good for "should not see")
|
|
417
|
-
}, [rowIdentifier, expectedText], function(result) {
|
|
418
|
-
if (result.value) {
|
|
419
|
-
throw new Error(`Found "${expectedText}" in the "${rowIdentifier}" row, but it should not be there.`);
|
|
420
547
|
}
|
|
421
548
|
});
|
|
422
549
|
});
|
|
@@ -441,8 +568,12 @@ When(/^(I |we )*reload( the)*( page)*$/, function (pronounCase, theCase, pageCas
|
|
|
441
568
|
*
|
|
442
569
|
*/
|
|
443
570
|
When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?"$/, function (pronounCase, field, value) {
|
|
571
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
572
|
+
browser.pause(500);
|
|
444
573
|
const elementField = browser.element.findByText(field, { exact: true });
|
|
445
574
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
575
|
+
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
576
|
+
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
446
577
|
return browser.setValue('#' + eleAttribute.value, value);
|
|
447
578
|
});
|
|
448
579
|
});
|
|
@@ -474,6 +605,7 @@ When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attr
|
|
|
474
605
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
475
606
|
}
|
|
476
607
|
|
|
608
|
+
browser.waitForElementPresent(selector, 5000);
|
|
477
609
|
return browser.setValue(selector, txtValue);
|
|
478
610
|
|
|
479
611
|
});
|
|
@@ -485,8 +617,12 @@ When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attr
|
|
|
485
617
|
*
|
|
486
618
|
*/
|
|
487
619
|
When(/^(I |we )*fill in "([^"]*)?" with:$/, function (pronounCase, field) {
|
|
620
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
621
|
+
browser.pause(500);
|
|
488
622
|
const elementField = browser.element.findByText(field, { exact: true });
|
|
489
623
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
624
|
+
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
625
|
+
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
490
626
|
return browser.setValue('#' + eleAttribute.value, '');
|
|
491
627
|
});
|
|
492
628
|
});
|
|
@@ -518,6 +654,7 @@ When(/^(I |we )*fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr
|
|
|
518
654
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
519
655
|
}
|
|
520
656
|
|
|
657
|
+
browser.waitForElementPresent(selector, 5000);
|
|
521
658
|
return browser.setValue(selector, '');
|
|
522
659
|
});
|
|
523
660
|
|
|
@@ -529,8 +666,12 @@ When(/^(I |we )*fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr
|
|
|
529
666
|
*
|
|
530
667
|
*/
|
|
531
668
|
When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?"$/, function (pronounCase, value, field) {
|
|
669
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
670
|
+
browser.pause(500);
|
|
532
671
|
const elementField = browser.element.findByText(field, { exact: true });
|
|
533
672
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
673
|
+
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
674
|
+
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
534
675
|
return browser.setValue('#' + eleAttribute.value, value);
|
|
535
676
|
});
|
|
536
677
|
});
|
|
@@ -562,7 +703,29 @@ When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attri
|
|
|
562
703
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
563
704
|
}
|
|
564
705
|
|
|
565
|
-
|
|
706
|
+
// Actively wait for dynamically generated element by polling the DOM
|
|
707
|
+
return browser.executeAsync(function(sel, value, done) {
|
|
708
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
709
|
+
var attempts = 0;
|
|
710
|
+
|
|
711
|
+
var checkElement = setInterval(function() {
|
|
712
|
+
var element = document.querySelector(sel);
|
|
713
|
+
attempts++;
|
|
714
|
+
|
|
715
|
+
if (element) {
|
|
716
|
+
clearInterval(checkElement);
|
|
717
|
+
element.value = value;
|
|
718
|
+
done({ found: true });
|
|
719
|
+
} else if (attempts >= maxAttempts) {
|
|
720
|
+
clearInterval(checkElement);
|
|
721
|
+
done({ found: false });
|
|
722
|
+
}
|
|
723
|
+
}, 500);
|
|
724
|
+
}, [selector, txtValue], function(result) {
|
|
725
|
+
if (!result || !result.value || !result.value.found) {
|
|
726
|
+
browser.assert.fail('Element "' + selector + '" was not found in dynamically generated content');
|
|
727
|
+
}
|
|
728
|
+
});
|
|
566
729
|
|
|
567
730
|
});
|
|
568
731
|
|
|
@@ -576,15 +739,22 @@ When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attri
|
|
|
576
739
|
|
|
577
740
|
When(/^(I |we )*fill in( the)* following:$/, function (pronounCase, theCase, table) {
|
|
578
741
|
|
|
742
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
743
|
+
browser.pause(500);
|
|
744
|
+
|
|
579
745
|
var elementField = browser.element.findByText(table.rawTable[0][0], { exact: true });
|
|
580
746
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
747
|
+
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
748
|
+
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
581
749
|
browser.setValue('#' + eleAttribute.value, table.rawTable[0][1]);
|
|
582
750
|
});
|
|
583
|
-
|
|
751
|
+
|
|
584
752
|
table.rows().forEach(row => {
|
|
585
753
|
|
|
586
754
|
elementField = browser.element.findByText(row[0], { exact: true });
|
|
587
755
|
browser.getAttribute(elementField, 'for', function (eleAttribute2) {
|
|
756
|
+
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
757
|
+
browser.waitForElementPresent('#' + eleAttribute2.value, 5000);
|
|
588
758
|
browser.setValue('#' + eleAttribute2.value, row[1]);
|
|
589
759
|
});
|
|
590
760
|
});
|
|
@@ -606,7 +776,7 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
|
|
|
606
776
|
|
|
607
777
|
var hasASpace = table.rawTable[0][0].indexOf(' ');
|
|
608
778
|
var selector = '';
|
|
609
|
-
|
|
779
|
+
|
|
610
780
|
if((table.rawTable[0][0].startsWith('#') || table.rawTable[0][0].startsWith('.')) && hasASpace == -1){
|
|
611
781
|
selector = table.rawTable[0][0];
|
|
612
782
|
}
|
|
@@ -620,9 +790,10 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
|
|
|
620
790
|
selector = '[' + attr + '="' + table.rawTable[0][0] + '"]';
|
|
621
791
|
}
|
|
622
792
|
|
|
793
|
+
browser.waitForElementPresent(selector, 5000);
|
|
623
794
|
browser.setValue(selector, table.rawTable[0][1]);
|
|
624
795
|
|
|
625
|
-
|
|
796
|
+
|
|
626
797
|
table.rows().forEach(row => {
|
|
627
798
|
|
|
628
799
|
hasASpace = row[0].indexOf(' ');
|
|
@@ -632,7 +803,7 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
|
|
|
632
803
|
selector = row[0];
|
|
633
804
|
}
|
|
634
805
|
else if (!attr && hasASpace == -1){
|
|
635
|
-
|
|
806
|
+
|
|
636
807
|
selector = row[0] + ',#' + row[0] + ',.' + row[0] + ',[name=' + row[0] + "]," + '[value="' + row[0] + '"],[placeholder="' + row[0] + '"]';
|
|
637
808
|
}
|
|
638
809
|
else if (!attr && hasASpace > -1){
|
|
@@ -642,6 +813,7 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
|
|
|
642
813
|
selector = '[' + attr + '="' + row[0] + '"]';
|
|
643
814
|
}
|
|
644
815
|
|
|
816
|
+
browser.waitForElementPresent(selector, 5000);
|
|
645
817
|
browser.setValue(selector, row[1]);
|
|
646
818
|
|
|
647
819
|
});
|
|
@@ -670,6 +842,12 @@ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, opti
|
|
|
670
842
|
selector = browser.element.findByText(selectList, { exact: true });
|
|
671
843
|
}
|
|
672
844
|
|
|
845
|
+
// Wait for select element to be present
|
|
846
|
+
if (typeof selector === 'string') {
|
|
847
|
+
browser.waitForElementPresent(selector, 5000);
|
|
848
|
+
}
|
|
849
|
+
browser.pause(300); // Allow dynamic options to render
|
|
850
|
+
|
|
673
851
|
let optionValue = '';
|
|
674
852
|
const result = option.toLowerCase();
|
|
675
853
|
|
|
@@ -679,7 +857,7 @@ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, opti
|
|
|
679
857
|
else{
|
|
680
858
|
optionValue = browser.element.findByText(option, { exact: true });
|
|
681
859
|
}
|
|
682
|
-
|
|
860
|
+
|
|
683
861
|
return browser.click(selector).click(optionValue).click(selector);
|
|
684
862
|
});
|
|
685
863
|
|
|
@@ -691,7 +869,51 @@ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, opti
|
|
|
691
869
|
*
|
|
692
870
|
*/
|
|
693
871
|
When(/^(I |we )*check "([^"]*)?"$/, function (pronounCase, item) {
|
|
694
|
-
|
|
872
|
+
// Actively wait for dynamically generated checkbox by polling the DOM
|
|
873
|
+
return browser.executeAsync(function(checkboxItem, done) {
|
|
874
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
875
|
+
var attempts = 0;
|
|
876
|
+
|
|
877
|
+
var checkCheckbox = setInterval(function() {
|
|
878
|
+
var element = null;
|
|
879
|
+
|
|
880
|
+
// Try to find checkbox by selector (e.g., #newsletter, .checkbox)
|
|
881
|
+
if (checkboxItem.startsWith('#') || checkboxItem.startsWith('.')) {
|
|
882
|
+
element = document.querySelector(checkboxItem);
|
|
883
|
+
} else {
|
|
884
|
+
// Try to find by label text
|
|
885
|
+
var labels = document.querySelectorAll('label');
|
|
886
|
+
for (var i = 0; i < labels.length; i++) {
|
|
887
|
+
var labelText = (labels[i].textContent || labels[i].innerText || '').trim();
|
|
888
|
+
if (labelText === checkboxItem) {
|
|
889
|
+
var forAttr = labels[i].getAttribute('for');
|
|
890
|
+
if (forAttr) {
|
|
891
|
+
element = document.getElementById(forAttr);
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
attempts++;
|
|
899
|
+
|
|
900
|
+
if (element) {
|
|
901
|
+
clearInterval(checkCheckbox);
|
|
902
|
+
element.checked = true;
|
|
903
|
+
// Trigger change event
|
|
904
|
+
var event = new Event('change', { bubbles: true });
|
|
905
|
+
element.dispatchEvent(event);
|
|
906
|
+
done({ found: true });
|
|
907
|
+
} else if (attempts >= maxAttempts) {
|
|
908
|
+
clearInterval(checkCheckbox);
|
|
909
|
+
done({ found: false });
|
|
910
|
+
}
|
|
911
|
+
}, 500);
|
|
912
|
+
}, [item], function(result) {
|
|
913
|
+
if (!result || !result.value || !result.value.found) {
|
|
914
|
+
browser.assert.fail('Checkbox "' + item + '" was not found in dynamically generated content');
|
|
915
|
+
}
|
|
916
|
+
});
|
|
695
917
|
});
|
|
696
918
|
|
|
697
919
|
/**
|
|
@@ -702,11 +924,137 @@ When(/^(I |we )*check "([^"]*)?"$/, function (pronounCase, item) {
|
|
|
702
924
|
*
|
|
703
925
|
*/
|
|
704
926
|
When(/^(I |we )*uncheck "([^"]*)?"$/, function (pronounCase, item) {
|
|
705
|
-
|
|
927
|
+
// Actively wait for dynamically generated checkbox by polling the DOM
|
|
928
|
+
return browser.executeAsync(function(checkboxItem, done) {
|
|
929
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
930
|
+
var attempts = 0;
|
|
931
|
+
|
|
932
|
+
var checkCheckbox = setInterval(function() {
|
|
933
|
+
var element = null;
|
|
934
|
+
|
|
935
|
+
// Try to find checkbox by selector (e.g., #newsletter, .checkbox)
|
|
936
|
+
if (checkboxItem.startsWith('#') || checkboxItem.startsWith('.')) {
|
|
937
|
+
element = document.querySelector(checkboxItem);
|
|
938
|
+
} else {
|
|
939
|
+
// Try to find by label text
|
|
940
|
+
var labels = document.querySelectorAll('label');
|
|
941
|
+
for (var i = 0; i < labels.length; i++) {
|
|
942
|
+
var labelText = (labels[i].textContent || labels[i].innerText || '').trim();
|
|
943
|
+
if (labelText === checkboxItem) {
|
|
944
|
+
var forAttr = labels[i].getAttribute('for');
|
|
945
|
+
if (forAttr) {
|
|
946
|
+
element = document.getElementById(forAttr);
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
attempts++;
|
|
954
|
+
|
|
955
|
+
if (element) {
|
|
956
|
+
clearInterval(checkCheckbox);
|
|
957
|
+
element.checked = false;
|
|
958
|
+
// Trigger change event
|
|
959
|
+
var event = new Event('change', { bubbles: true });
|
|
960
|
+
element.dispatchEvent(event);
|
|
961
|
+
done({ found: true });
|
|
962
|
+
} else if (attempts >= maxAttempts) {
|
|
963
|
+
clearInterval(checkCheckbox);
|
|
964
|
+
done({ found: false });
|
|
965
|
+
}
|
|
966
|
+
}, 500);
|
|
967
|
+
}, [item], function(result) {
|
|
968
|
+
if (!result || !result.value || !result.value.found) {
|
|
969
|
+
browser.assert.fail('Checkbox "' + item + '" was not found in dynamically generated content');
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Selects radio button specified by label text, value, or selector.
|
|
976
|
+
*
|
|
977
|
+
* Example #1: When I select radio button "Male"
|
|
978
|
+
* Example #2: When I select radio button "female"
|
|
979
|
+
* Example #3: When I select radio button "#gender-male"
|
|
980
|
+
* Example #4: When we select radio button "option1"
|
|
981
|
+
*
|
|
982
|
+
*/
|
|
983
|
+
When(/^(I |we )*select radio button "([^"]*)?"$/, function (pronounCase, item) {
|
|
984
|
+
// Actively wait for dynamically generated radio button by polling the DOM
|
|
985
|
+
return browser.executeAsync(function(radioItem, done) {
|
|
986
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
987
|
+
var attempts = 0;
|
|
988
|
+
|
|
989
|
+
var selectRadio = setInterval(function() {
|
|
990
|
+
var element = null;
|
|
991
|
+
|
|
992
|
+
// Try to find radio button by selector (e.g., #gender-male, .radio-option)
|
|
993
|
+
if (radioItem.startsWith('#') || radioItem.startsWith('.')) {
|
|
994
|
+
var foundElement = document.querySelector(radioItem);
|
|
995
|
+
if (foundElement && foundElement.type === 'radio') {
|
|
996
|
+
element = foundElement;
|
|
997
|
+
}
|
|
998
|
+
} else {
|
|
999
|
+
// Try to find by value attribute first
|
|
1000
|
+
var radioButtons = document.querySelectorAll('input[type="radio"]');
|
|
1001
|
+
for (var i = 0; i < radioButtons.length; i++) {
|
|
1002
|
+
if (radioButtons[i].value === radioItem) {
|
|
1003
|
+
element = radioButtons[i];
|
|
1004
|
+
break;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// If not found by value, try to find by label text
|
|
1009
|
+
if (!element) {
|
|
1010
|
+
var labels = document.querySelectorAll('label');
|
|
1011
|
+
for (var j = 0; j < labels.length; j++) {
|
|
1012
|
+
var labelText = (labels[j].textContent || labels[j].innerText || '').trim();
|
|
1013
|
+
if (labelText === radioItem) {
|
|
1014
|
+
var forAttr = labels[j].getAttribute('for');
|
|
1015
|
+
if (forAttr) {
|
|
1016
|
+
var radioElement = document.getElementById(forAttr);
|
|
1017
|
+
if (radioElement && radioElement.type === 'radio') {
|
|
1018
|
+
element = radioElement;
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
// Also check if label wraps the radio input
|
|
1023
|
+
var radioInput = labels[j].querySelector('input[type="radio"]');
|
|
1024
|
+
if (radioInput) {
|
|
1025
|
+
element = radioInput;
|
|
1026
|
+
break;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
attempts++;
|
|
1034
|
+
|
|
1035
|
+
if (element) {
|
|
1036
|
+
clearInterval(selectRadio);
|
|
1037
|
+
element.checked = true;
|
|
1038
|
+
// Trigger change and click events for better compatibility
|
|
1039
|
+
var changeEvent = new Event('change', { bubbles: true });
|
|
1040
|
+
var clickEvent = new Event('click', { bubbles: true });
|
|
1041
|
+
element.dispatchEvent(clickEvent);
|
|
1042
|
+
element.dispatchEvent(changeEvent);
|
|
1043
|
+
done({ found: true, value: element.value, name: element.name });
|
|
1044
|
+
} else if (attempts >= maxAttempts) {
|
|
1045
|
+
clearInterval(selectRadio);
|
|
1046
|
+
done({ found: false });
|
|
1047
|
+
}
|
|
1048
|
+
}, 500);
|
|
1049
|
+
}, [item], function(result) {
|
|
1050
|
+
if (!result || !result.value || !result.value.found) {
|
|
1051
|
+
browser.assert.fail('Radio button "' + item + '" was not found in dynamically generated content');
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
706
1054
|
});
|
|
707
1055
|
|
|
708
1056
|
/**
|
|
709
|
-
* Verify, that current page is the homepage.
|
|
1057
|
+
* Verify, that current page is or is not the homepage.
|
|
710
1058
|
*
|
|
711
1059
|
* Example #1: Then I should be on homepage
|
|
712
1060
|
* Example #2: And I should be on the homepage
|
|
@@ -716,30 +1064,25 @@ When(/^(I |we )*uncheck "([^"]*)?"$/, function (pronounCase, item) {
|
|
|
716
1064
|
* Example #6: And we should be on homepage
|
|
717
1065
|
* Example #7: Then should be on frontpage
|
|
718
1066
|
* Example #8: And we should be on the homepage
|
|
719
|
-
*
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
*
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
* Example #7: And we should not be on the homepage
|
|
735
|
-
*
|
|
736
|
-
*/
|
|
737
|
-
Then(/^(I |we )*should not be on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
|
|
738
|
-
return browser.assert.not.urlMatches(browser.launch_url);
|
|
1067
|
+
* Example #9: Then I should not be on homepage
|
|
1068
|
+
* Example #10: And I should not be on the homepage
|
|
1069
|
+
* Example #11: Then I should not be on frontpage
|
|
1070
|
+
* Example #12: Then we should not be on homepage
|
|
1071
|
+
* Example #13: Then should not be on the homepage
|
|
1072
|
+
* Example #14: And we should not be on frontpage
|
|
1073
|
+
* Example #15: And we should not be on the homepage
|
|
1074
|
+
*
|
|
1075
|
+
*/
|
|
1076
|
+
Then(/^(I |we )*should( not)* be on( the)* (homepage|frontpage)$/, function (pronounCase, notCase, theCase, pageCase) {
|
|
1077
|
+
if (notCase) {
|
|
1078
|
+
return browser.assert.not.urlMatches(browser.launch_url);
|
|
1079
|
+
} else {
|
|
1080
|
+
return browser.assert.urlMatches(browser.launch_url);
|
|
1081
|
+
}
|
|
739
1082
|
});
|
|
740
1083
|
|
|
741
1084
|
/**
|
|
742
|
-
* Verify, that current page path is equal to specified path.
|
|
1085
|
+
* Verify, that current page path is equal or not equal to specified path.
|
|
743
1086
|
*
|
|
744
1087
|
* Example #1: Then I should be on "/"
|
|
745
1088
|
* Example #2: And I should be on "/user/login"
|
|
@@ -749,27 +1092,22 @@ Then(/^(I |we )*should not be on( the)* (homepage|frontpage)$/, function (pronou
|
|
|
749
1092
|
* Example #6: And we should be on "https://google.com"
|
|
750
1093
|
* Example #7: Then should be on the "/user/reset" page
|
|
751
1094
|
* Example #8: And we should be on "https://x.com"
|
|
752
|
-
*
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
|
|
762
|
-
*
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
* Example #8: And we should not be on the "https://x.com" page
|
|
769
|
-
*
|
|
770
|
-
*/
|
|
771
|
-
Then(/^(I |we )*should not be on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
|
|
772
|
-
return browser.assert.not.urlContains(url);
|
|
1095
|
+
* Example #9: Then I should not be on "/"
|
|
1096
|
+
* Example #10: And I should not be on "/user/login"
|
|
1097
|
+
* Example #11: And I should not be on "https://un.org"
|
|
1098
|
+
* Example #12: Then we should not be on the "/" page
|
|
1099
|
+
* Example #13: And we should not be on "/user/login"
|
|
1100
|
+
* Example #14: Then we should not be on "https://google.com"
|
|
1101
|
+
* Example #15: And should not be on "/user/reset"
|
|
1102
|
+
* Example #16: And we should not be on the "https://x.com" page
|
|
1103
|
+
*
|
|
1104
|
+
*/
|
|
1105
|
+
Then(/^(I |we )*should( not)* be on( the)* "([^"]*)?"( page)*$/, function (pronounCase, notCase, theCase, url, pageCase) {
|
|
1106
|
+
if (notCase) {
|
|
1107
|
+
return browser.assert.not.urlContains(url);
|
|
1108
|
+
} else {
|
|
1109
|
+
return browser.assert.urlContains(url);
|
|
1110
|
+
}
|
|
773
1111
|
});
|
|
774
1112
|
|
|
775
1113
|
/**
|
|
@@ -779,7 +1117,11 @@ Then(/^(I |we )*should not be on( the)* "([^"]*)?"( page)*$/, function (pronounC
|
|
|
779
1117
|
*
|
|
780
1118
|
*/
|
|
781
1119
|
Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, function (theCase, element, url) {
|
|
1120
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
1121
|
+
browser.pause(500);
|
|
782
1122
|
const elementField = browser.element.findByText(element, { exact: true });
|
|
1123
|
+
// Wait for link to be present (handles dynamically generated links)
|
|
1124
|
+
browser.waitForElementPresent(elementField, 5000);
|
|
783
1125
|
return browser.assert.attributeContains(elementField, 'href', url);
|
|
784
1126
|
});
|
|
785
1127
|
|
|
@@ -793,6 +1135,9 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, function (theCase, el
|
|
|
793
1135
|
*/
|
|
794
1136
|
Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (theCase, attrValue, url, itsCase, attr, attrCase) {
|
|
795
1137
|
|
|
1138
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
1139
|
+
browser.pause(500);
|
|
1140
|
+
|
|
796
1141
|
const hasASpace = attrValue.indexOf(' ');
|
|
797
1142
|
var selector = '';
|
|
798
1143
|
|
|
@@ -809,62 +1154,92 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")*
|
|
|
809
1154
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
810
1155
|
}
|
|
811
1156
|
|
|
1157
|
+
// Wait for link to be present (handles dynamically generated links)
|
|
1158
|
+
browser.waitForElementPresent(selector, 5000);
|
|
812
1159
|
return browser.assert.attributeContains(selector, 'href', url);
|
|
813
1160
|
});
|
|
814
1161
|
|
|
815
1162
|
/**
|
|
816
|
-
* Checks, that HTML response contains specific text.
|
|
1163
|
+
* Checks, that HTML response contains or does not contain specific text.
|
|
817
1164
|
*
|
|
818
1165
|
* Example #1: Then the response should contain "Welcome visitor, How can I help you?"
|
|
1166
|
+
* Example #2: Then the response should not contain "Welcome visitor, How can I help you?"
|
|
819
1167
|
*
|
|
820
1168
|
*/
|
|
821
|
-
Then(/^(the )*response should contain "([^"]*)?"$/, function (theCase, expectedText) {
|
|
822
|
-
return this.shouldSee = function (browser) {
|
|
823
|
-
browser.assert.textContains("html", expectedText);
|
|
824
|
-
};
|
|
825
|
-
});
|
|
826
|
-
|
|
827
|
-
/**
|
|
828
|
-
* Checks, that HTML response dose not contains specific text.
|
|
829
|
-
*
|
|
830
|
-
* Example #1: Then the response should not contain "Welcome visitor, How can I help you?"
|
|
831
|
-
*
|
|
832
|
-
*/
|
|
833
|
-
Then(/^(the )*response should not contain "([^"]*)?"$/, function (theCase, expectedText) {
|
|
1169
|
+
Then(/^(the )*response should( not)* contain "([^"]*)?"$/, function (theCase, notCase, expectedText) {
|
|
834
1170
|
return this.shouldSee = function (browser) {
|
|
835
|
-
|
|
1171
|
+
if (notCase) {
|
|
1172
|
+
browser.assert.not.textContains("html", expectedText);
|
|
1173
|
+
} else {
|
|
1174
|
+
browser.assert.textContains("html", expectedText);
|
|
1175
|
+
}
|
|
836
1176
|
};
|
|
837
1177
|
});
|
|
838
1178
|
|
|
839
1179
|
/**
|
|
840
|
-
* Assert, that input text contains a specific value by its label.
|
|
1180
|
+
* Assert, that input text contains or does not contain a specific value by its label.
|
|
841
1181
|
*
|
|
842
1182
|
* Example #1: Then I should see "John Smith" in the "Username" element
|
|
843
1183
|
* Example #2: Then I should not see "Joe Smith" in the "Username" element
|
|
844
|
-
*
|
|
1184
|
+
*
|
|
845
1185
|
*/
|
|
846
|
-
Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText, theCase
|
|
1186
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, notCase, expectedText, theCase, element) {
|
|
1187
|
+
// Wait for dynamic content to load
|
|
1188
|
+
browser.pause(500);
|
|
1189
|
+
|
|
847
1190
|
const elementField = browser.element.findByText(element, { exact: true });
|
|
848
1191
|
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
1192
|
+
// Wait for the element to be present (handles dynamically generated elements)
|
|
1193
|
+
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
1194
|
+
|
|
849
1195
|
return this.shouldSee = function (browser) {
|
|
850
|
-
|
|
1196
|
+
// Check dynamically rendered content in the element
|
|
1197
|
+
browser.execute(function(selector, text) {
|
|
1198
|
+
const elem = document.querySelector(selector);
|
|
1199
|
+
if (!elem) return null;
|
|
1200
|
+
const content = elem.textContent || elem.innerText || elem.value || '';
|
|
1201
|
+
return content.includes(text);
|
|
1202
|
+
}, ['#' + eleAttribute.value, expectedText], function(result) {
|
|
1203
|
+
if (result.value === null) {
|
|
1204
|
+
browser.assert.fail(`Element with ID "${eleAttribute.value}" not found`);
|
|
1205
|
+
} else if (notCase) {
|
|
1206
|
+
if (result.value) {
|
|
1207
|
+
browser.assert.fail(`Text "${expectedText}" should not be in element`);
|
|
1208
|
+
}
|
|
1209
|
+
} else {
|
|
1210
|
+
if (!result.value) {
|
|
1211
|
+
browser.assert.fail(`Text "${expectedText}" should be in element`);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
|
|
1216
|
+
if (notCase) {
|
|
1217
|
+
browser.assert.not.textContains('#' + eleAttribute.value, expectedText);
|
|
1218
|
+
} else {
|
|
1219
|
+
browser.assert.textContains('#' + eleAttribute.value, expectedText);
|
|
1220
|
+
}
|
|
851
1221
|
};
|
|
852
1222
|
});
|
|
853
1223
|
});
|
|
854
1224
|
|
|
855
1225
|
/**
|
|
856
|
-
* Assert, that input text contains a specific value by its attributes.
|
|
1226
|
+
* Assert, that input text contains or does not contain a specific value by its attributes.
|
|
1227
|
+
*
|
|
1228
|
+
* Example #1: Then I should see "John Smith" in the "uname" element by its "id" attr
|
|
1229
|
+
* Example #2: Then I should see "1234" in the "pwordcss" element by attr
|
|
1230
|
+
* Example #3: Then I should not see "John Smith" in the "uname" element by its "id" attr
|
|
1231
|
+
* Example #4: Then I should not see "1234" in the "pwordcss" element by attr
|
|
857
1232
|
*
|
|
858
|
-
* Example: Then I should see "John Smith" in the "uname" element by its "id" attr
|
|
859
|
-
* Example: Then I should see "1234" in the "pwordcss" element by attr
|
|
860
|
-
*
|
|
861
1233
|
*/
|
|
862
|
-
Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
|
|
1234
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, notCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
|
|
863
1235
|
|
|
864
1236
|
const hasASpace = attrValue.indexOf(' ');
|
|
865
1237
|
|
|
866
1238
|
var selector = '';
|
|
867
|
-
if (
|
|
1239
|
+
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
1240
|
+
selector = attrValue;
|
|
1241
|
+
}
|
|
1242
|
+
else if (!attr && hasASpace == -1){
|
|
868
1243
|
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
869
1244
|
}
|
|
870
1245
|
else if (!attr && hasASpace > -1){
|
|
@@ -874,35 +1249,77 @@ Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "(
|
|
|
874
1249
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
875
1250
|
}
|
|
876
1251
|
|
|
877
|
-
return
|
|
878
|
-
|
|
879
|
-
|
|
1252
|
+
return browser.executeAsync(function(sel, text, shouldContain, done) {
|
|
1253
|
+
var maxAttempts = 20;
|
|
1254
|
+
var attempts = 0;
|
|
1255
|
+
|
|
1256
|
+
var checkElement = setInterval(function() {
|
|
1257
|
+
var elem = document.querySelector(sel);
|
|
1258
|
+
attempts++;
|
|
1259
|
+
|
|
1260
|
+
if (elem) {
|
|
1261
|
+
clearInterval(checkElement);
|
|
1262
|
+
var content = elem.textContent || elem.innerText || elem.value || '';
|
|
1263
|
+
var containsText = content.includes(text);
|
|
1264
|
+
done({ found: true, containsText: containsText, actualContent: content });
|
|
1265
|
+
} else if (attempts >= maxAttempts) {
|
|
1266
|
+
clearInterval(checkElement);
|
|
1267
|
+
done({ found: false, containsText: false, actualContent: null });
|
|
1268
|
+
}
|
|
1269
|
+
}, 500);
|
|
1270
|
+
}, [selector, expectedText, !notCase], function(result) {
|
|
1271
|
+
if (!result || !result.value || !result.value.found) {
|
|
1272
|
+
browser.assert.fail('Element matching selector "' + selector + '" was not found');
|
|
1273
|
+
} else {
|
|
1274
|
+
if (notCase) {
|
|
1275
|
+
if (result.value.containsText) {
|
|
1276
|
+
browser.assert.fail('Text "' + expectedText + '" should not be in element "' + selector + '" but it is. Content: ' + result.value.actualContent);
|
|
1277
|
+
}
|
|
1278
|
+
} else {
|
|
1279
|
+
if (!result.value.containsText) {
|
|
1280
|
+
browser.assert.fail('Text "' + expectedText + '" should be in element "' + selector + '" but it is not. Content: ' + result.value.actualContent);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
880
1285
|
});
|
|
881
1286
|
|
|
882
1287
|
/**
|
|
883
|
-
* Assert, that
|
|
1288
|
+
* Assert, that element exists or does not exist on current page by its label.
|
|
884
1289
|
*
|
|
885
|
-
* Example: Then I should
|
|
1290
|
+
* Example #1: Then I should see a "Username" element
|
|
1291
|
+
* Example #2: Then I should not see a "Username" element
|
|
886
1292
|
*
|
|
887
1293
|
*/
|
|
888
|
-
Then(/^(I |we )*should not see
|
|
1294
|
+
Then(/^(I |we )*should( not)* see (a|an) "([^"]*)?" element$/, function (pronounCase, notCase, aAnCase, element) {
|
|
1295
|
+
// Wait for elements that might be dynamically rendered
|
|
1296
|
+
browser.pause(500);
|
|
889
1297
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1298
|
+
if (notCase) {
|
|
1299
|
+
browser.assert.not.textContains("html", element);
|
|
1300
|
+
} else {
|
|
1301
|
+
// Wait for element to be rendered by JavaScript
|
|
1302
|
+
browser.waitForElementPresent('body', 2000);
|
|
1303
|
+
|
|
1304
|
+
const elementField = browser.element.findByText(element, { exact: true });
|
|
1305
|
+
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
1306
|
+
// Wait for the specific element to be visible (in case it's AJAX-loaded)
|
|
1307
|
+
browser.waitForElementVisible('#' + eleAttribute.value, 3000);
|
|
1308
|
+
return browser.verify.visible('#' + eleAttribute.value);
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
896
1311
|
});
|
|
897
1312
|
|
|
898
1313
|
/**
|
|
899
|
-
* Assert, that
|
|
1314
|
+
* Assert, that element exists or does not exist on the current page by its attribute.
|
|
1315
|
+
*
|
|
1316
|
+
* Example #1: Then I should see a "uname" element by its "id" attr
|
|
1317
|
+
* Example #2: Then I should see a "pwordcss" element by attr
|
|
1318
|
+
* Example #3: Then I should not see an "emailId" element by its "id" attr
|
|
1319
|
+
* Example #4: And I should not see a "countryCss" element by attr
|
|
900
1320
|
*
|
|
901
|
-
* Example: Then I should not see "John Smith" in the "uname" element by its "id" attr
|
|
902
|
-
* Example: Then I should not see "1234" in the "pwordcss" element by attr
|
|
903
|
-
*
|
|
904
1321
|
*/
|
|
905
|
-
Then(/^(I |we )*should not see
|
|
1322
|
+
Then(/^(I |we )*should( not)* see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, notCase, aAnCase, attrValue, itsCase, attr, attrCase) {
|
|
906
1323
|
|
|
907
1324
|
const hasASpace = attrValue.indexOf(' ');
|
|
908
1325
|
|
|
@@ -917,256 +1334,493 @@ Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*
|
|
|
917
1334
|
selector = '[' + attr + '="' + attrValue + '"]';
|
|
918
1335
|
}
|
|
919
1336
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1337
|
+
// Wait for dynamic content
|
|
1338
|
+
browser.pause(500);
|
|
1339
|
+
|
|
1340
|
+
if (notCase) {
|
|
1341
|
+
return browser.expect.element(selector).to.not.be.present;
|
|
1342
|
+
} else {
|
|
1343
|
+
// Wait for element to be rendered and visible (for AJAX/JS content)
|
|
1344
|
+
browser.waitForElementVisible(selector, 3000);
|
|
1345
|
+
return browser.verify.visible(selector);
|
|
1346
|
+
}
|
|
923
1347
|
});
|
|
924
1348
|
|
|
1349
|
+
|
|
925
1350
|
/**
|
|
926
|
-
* Assert, that element
|
|
1351
|
+
* Assert, that element contains or does not contain a specific CSS style.
|
|
927
1352
|
*
|
|
928
|
-
* Example: Then
|
|
1353
|
+
* Example #1: Then the "body" element should contain "color:white;"
|
|
1354
|
+
* Example #2: Then the "body" element should not contain "color:white;"
|
|
1355
|
+
* Example #3: Then the "#uname" element should not contain "border:solid 5px red;"
|
|
1356
|
+
* Example #4: Then the "pword" element should not contain "font-size: 26px;"
|
|
929
1357
|
*
|
|
930
1358
|
*/
|
|
931
|
-
Then(/^(
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
1359
|
+
Then(/^(the )*"([^"]*)?" element should( not)* contain "([^"]*)?"$/, function (theCase, selector, notCase, elementCss) {
|
|
1360
|
+
|
|
1361
|
+
elementCss = elementCss.replace(";", '');
|
|
1362
|
+
const cssPropertyArr = elementCss.split(":");
|
|
1363
|
+
|
|
1364
|
+
const cssProperty = cssPropertyArr[0].trim();
|
|
1365
|
+
const propertyVal = cssPropertyArr[1].trim();
|
|
1366
|
+
|
|
1367
|
+
return browser.executeAsync(function(sel, cssProp, done) {
|
|
1368
|
+
var maxAttempts = 20;
|
|
1369
|
+
var attempts = 0;
|
|
1370
|
+
|
|
1371
|
+
var checkElement = setInterval(function() {
|
|
1372
|
+
var element = document.querySelector(sel);
|
|
1373
|
+
attempts++;
|
|
1374
|
+
|
|
1375
|
+
if (element) {
|
|
1376
|
+
clearInterval(checkElement);
|
|
1377
|
+
var computedStyle = window.getComputedStyle(element);
|
|
1378
|
+
var actualValue = computedStyle.getPropertyValue(cssProp);
|
|
1379
|
+
done({ found: true, value: actualValue });
|
|
1380
|
+
} else if (attempts >= maxAttempts) {
|
|
1381
|
+
clearInterval(checkElement);
|
|
1382
|
+
done({ found: false, value: null });
|
|
1383
|
+
}
|
|
1384
|
+
}, 500);
|
|
1385
|
+
}, [selector, cssProperty], function(result) {
|
|
1386
|
+
if (!result || !result.value || !result.value.found) {
|
|
1387
|
+
browser.assert.fail('Element "' + selector + '" was not found');
|
|
1388
|
+
} else {
|
|
1389
|
+
var actualValue = (result.value.value || '').trim();
|
|
1390
|
+
var expectedValue = propertyVal.trim();
|
|
1391
|
+
|
|
1392
|
+
if (notCase) {
|
|
1393
|
+
if (actualValue === expectedValue) {
|
|
1394
|
+
browser.assert.fail('Element "' + selector + '" should not contain CSS "' + cssProperty + ': ' + expectedValue + '" but it does');
|
|
1395
|
+
}
|
|
1396
|
+
} else {
|
|
1397
|
+
if (actualValue !== expectedValue) {
|
|
1398
|
+
browser.assert.fail('Element "' + selector + '" should contain CSS "' + cssProperty + ': ' + expectedValue + '" but has "' + actualValue + '"');
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
935
1402
|
});
|
|
936
1403
|
});
|
|
937
1404
|
|
|
938
1405
|
/**
|
|
939
|
-
* Assert, that
|
|
1406
|
+
* Assert, that field contains or does not contain a specific text.
|
|
1407
|
+
*
|
|
1408
|
+
* Example #1: Then the "Username" field should contain "John Smith"
|
|
1409
|
+
* Example #2: Then the "#username" field should not contain "John Smith"
|
|
940
1410
|
*
|
|
941
|
-
* Example: Then I should see a "uname" element by its "id" attr
|
|
942
|
-
* Example: Then I should see a "pwordcss" element by attr
|
|
943
|
-
*
|
|
944
1411
|
*/
|
|
945
|
-
Then(/^(
|
|
946
|
-
|
|
947
|
-
|
|
1412
|
+
Then(/^(the )*"([^"]*)?" field should( not)* contain "([^"]*)?"$/, function (theCase, field, notCase, expectedText) {
|
|
1413
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
1414
|
+
browser.pause(500);
|
|
948
1415
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1416
|
+
if (notCase) {
|
|
1417
|
+
// Wait for field to be present (handles dynamically generated fields)
|
|
1418
|
+
browser.waitForElementPresent(field, 5000);
|
|
1419
|
+
return this.shouldSee = function (browser) {
|
|
1420
|
+
browser.assert.not.textContains(field, expectedText);
|
|
1421
|
+
};
|
|
1422
|
+
} else {
|
|
1423
|
+
const elementField = browser.element.findByText(field, { exact: true });
|
|
1424
|
+
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
1425
|
+
// Wait for the input field to be present (handles dynamically generated form fields)
|
|
1426
|
+
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
1427
|
+
return this.shouldSee = function (browser) {
|
|
1428
|
+
browser.assert.textContains('#' + eleAttribute.value, expectedText);
|
|
1429
|
+
};
|
|
1430
|
+
});
|
|
952
1431
|
}
|
|
953
|
-
else if (!attr && hasASpace > -1){
|
|
954
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
955
|
-
}
|
|
956
|
-
else {
|
|
957
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
return browser.verify.visible(selector);
|
|
961
1432
|
});
|
|
962
1433
|
|
|
963
1434
|
/**
|
|
964
|
-
* Assert, that
|
|
1435
|
+
* Assert, that checkbox with specified element is or is not checked.
|
|
965
1436
|
*
|
|
966
|
-
* Example: Then
|
|
1437
|
+
* Example #1: Then the "#PrivacyPolicy" checkbox should be checked
|
|
1438
|
+
* Example #2: Then the "#PrivacyPolicy" checkbox should not be checked
|
|
967
1439
|
*
|
|
968
1440
|
*/
|
|
969
|
-
Then(/^(
|
|
970
|
-
|
|
1441
|
+
Then(/^(the )*"([^"]*)?" checkbox should( not)* be checked$/, function (theCase, checkbox, notCase) {
|
|
1442
|
+
// Actively wait for dynamically generated checkbox by polling the DOM
|
|
1443
|
+
return browser.executeAsync(function(checkboxSelector, shouldBeChecked, done) {
|
|
1444
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
1445
|
+
var attempts = 0;
|
|
1446
|
+
|
|
1447
|
+
var checkCheckbox = setInterval(function() {
|
|
1448
|
+
var element = document.querySelector(checkboxSelector);
|
|
1449
|
+
attempts++;
|
|
1450
|
+
|
|
1451
|
+
if (element) {
|
|
1452
|
+
clearInterval(checkCheckbox);
|
|
1453
|
+
var isChecked = element.checked;
|
|
1454
|
+
done({ found: true, checked: isChecked });
|
|
1455
|
+
} else if (attempts >= maxAttempts) {
|
|
1456
|
+
clearInterval(checkCheckbox);
|
|
1457
|
+
done({ found: false, checked: false });
|
|
1458
|
+
}
|
|
1459
|
+
}, 500);
|
|
1460
|
+
}, [checkbox, !notCase], function(result) {
|
|
1461
|
+
if (!result || !result.value || !result.value.found) {
|
|
1462
|
+
browser.assert.fail('Checkbox "' + checkbox + '" was not found in dynamically generated content');
|
|
1463
|
+
} else {
|
|
1464
|
+
if (notCase) {
|
|
1465
|
+
if (result.value.checked) {
|
|
1466
|
+
browser.assert.fail('Checkbox "' + checkbox + '" should not be checked but it is');
|
|
1467
|
+
}
|
|
1468
|
+
} else {
|
|
1469
|
+
if (!result.value.checked) {
|
|
1470
|
+
browser.assert.fail('Checkbox "' + checkbox + '" should be checked but it is not');
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
971
1475
|
});
|
|
972
1476
|
|
|
973
1477
|
/**
|
|
974
|
-
*
|
|
1478
|
+
* Check, whether the checkbox specified is or is not checked.
|
|
975
1479
|
*
|
|
976
|
-
* Example: Then
|
|
977
|
-
* Example:
|
|
1480
|
+
* Example #1: Then the "#rememberMe" checkbox is checked
|
|
1481
|
+
* Example #2: Then the "#rememberMe" checkbox is not checked
|
|
978
1482
|
*
|
|
979
1483
|
*/
|
|
980
|
-
Then(/^(
|
|
981
|
-
|
|
982
|
-
|
|
1484
|
+
Then(/^(the )*"([^"]*)?" checkbox is( not)* checked$/, function (theCase, checkbox, notCase) {
|
|
1485
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
1486
|
+
browser.pause(500);
|
|
1487
|
+
// Wait for checkbox to be present (handles dynamically generated checkboxes)
|
|
1488
|
+
browser.waitForElementPresent(checkbox, 5000);
|
|
983
1489
|
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
else if (!attr && hasASpace > -1){
|
|
989
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
990
|
-
}
|
|
991
|
-
else {
|
|
992
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
1490
|
+
if (notCase) {
|
|
1491
|
+
return browser.expect.element(checkbox).to.not.be.selected;
|
|
1492
|
+
} else {
|
|
1493
|
+
return browser.expect.element(checkbox).to.be.selected;
|
|
993
1494
|
}
|
|
994
|
-
|
|
995
|
-
return browser.expect.element(selector).to.not.be.present;
|
|
996
1495
|
});
|
|
997
1496
|
|
|
998
1497
|
/**
|
|
999
|
-
* Assert, that element
|
|
1498
|
+
* Assert, that checkbox with specified element should or should not be checked.
|
|
1000
1499
|
*
|
|
1001
|
-
* Example: Then the "
|
|
1500
|
+
* Example #1: Then the checkbox "#PrivacyPolicy" should be checked
|
|
1501
|
+
* Example #2: Then the checkbox "#PrivacyPolicy" should not be checked
|
|
1002
1502
|
*
|
|
1003
1503
|
*/
|
|
1004
|
-
Then(/^(the )*"([^"]*)?"
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1504
|
+
Then(/^(the )*checkbox "([^"]*)?" should( not)* be checked$/, function (theCase, checkbox, notCase) {
|
|
1505
|
+
return browser.executeAsync(function(checkboxSelector, shouldBeChecked, done) {
|
|
1506
|
+
var maxAttempts = 20;
|
|
1507
|
+
var attempts = 0;
|
|
1008
1508
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1509
|
+
var checkCheckbox = setInterval(function() {
|
|
1510
|
+
var element = document.querySelector(checkboxSelector);
|
|
1511
|
+
attempts++;
|
|
1011
1512
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1513
|
+
if (element) {
|
|
1514
|
+
clearInterval(checkCheckbox);
|
|
1515
|
+
var isChecked = element.checked;
|
|
1516
|
+
done({ found: true, checked: isChecked });
|
|
1517
|
+
} else if (attempts >= maxAttempts) {
|
|
1518
|
+
clearInterval(checkCheckbox);
|
|
1519
|
+
done({ found: false, checked: false });
|
|
1520
|
+
}
|
|
1521
|
+
}, 500);
|
|
1522
|
+
}, [checkbox, !notCase], function(result) {
|
|
1523
|
+
if (!result || !result.value || !result.value.found) {
|
|
1524
|
+
browser.assert.fail('Checkbox "' + checkbox + '" was not found');
|
|
1525
|
+
} else {
|
|
1526
|
+
if (notCase) {
|
|
1527
|
+
if (result.value.checked) {
|
|
1528
|
+
browser.assert.fail('Checkbox "' + checkbox + '" should not be checked but it is');
|
|
1529
|
+
}
|
|
1530
|
+
} else {
|
|
1531
|
+
if (!result.value.checked) {
|
|
1532
|
+
browser.assert.fail('Checkbox "' + checkbox + '" should be checked but it is not');
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1015
1537
|
});
|
|
1016
1538
|
|
|
1017
1539
|
/**
|
|
1018
|
-
* Assert, that element
|
|
1540
|
+
* Assert, that checkbox with specified element is or is not checked.
|
|
1541
|
+
*
|
|
1542
|
+
* Example #1: Then the checkbox "#rememberMe" is checked
|
|
1543
|
+
* Example #2: Then the checkbox "#rememberMe" is not checked
|
|
1019
1544
|
*
|
|
1020
|
-
* Example #1: Then the "body" element should not contain "color:white;"
|
|
1021
|
-
* Example #2: Then the "#uname" element should not contain "border:solid 5px red;"
|
|
1022
|
-
* Example #3: Then the "pword" element should not contain "font-size: 26px;"
|
|
1023
1545
|
*/
|
|
1024
|
-
Then(/^(the )*"([^"]*)?"
|
|
1546
|
+
Then(/^(the )*checkbox "([^"]*)?" is( not)* checked$/, function (theCase, checkbox, notCase) {
|
|
1547
|
+
return browser.executeAsync(function(checkboxSelector, shouldBeChecked, done) {
|
|
1548
|
+
var maxAttempts = 20;
|
|
1549
|
+
var attempts = 0;
|
|
1025
1550
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
const cssProperty = cssPropertyArr[0].trim();
|
|
1030
|
-
const propertyVal = cssPropertyArr[1].trim();
|
|
1551
|
+
var checkCheckbox = setInterval(function() {
|
|
1552
|
+
var element = document.querySelector(checkboxSelector);
|
|
1553
|
+
attempts++;
|
|
1031
1554
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1555
|
+
if (element) {
|
|
1556
|
+
clearInterval(checkCheckbox);
|
|
1557
|
+
var isChecked = element.checked;
|
|
1558
|
+
done({ found: true, checked: isChecked });
|
|
1559
|
+
} else if (attempts >= maxAttempts) {
|
|
1560
|
+
clearInterval(checkCheckbox);
|
|
1561
|
+
done({ found: false, checked: false });
|
|
1562
|
+
}
|
|
1563
|
+
}, 500);
|
|
1564
|
+
}, [checkbox, !notCase], function(result) {
|
|
1565
|
+
if (!result || !result.value || !result.value.found) {
|
|
1566
|
+
browser.assert.fail('Checkbox "' + checkbox + '" was not found');
|
|
1567
|
+
} else {
|
|
1568
|
+
if (notCase) {
|
|
1569
|
+
if (result.value.checked) {
|
|
1570
|
+
browser.assert.fail('Checkbox "' + checkbox + '" should not be checked but it is');
|
|
1571
|
+
}
|
|
1572
|
+
} else {
|
|
1573
|
+
if (!result.value.checked) {
|
|
1574
|
+
browser.assert.fail('Checkbox "' + checkbox + '" should be checked but it is not');
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1035
1579
|
});
|
|
1036
1580
|
|
|
1037
1581
|
/**
|
|
1038
|
-
*
|
|
1582
|
+
* Assert, that radio button with specified selector should or should not be selected.
|
|
1039
1583
|
*
|
|
1040
|
-
* Example:
|
|
1584
|
+
* Example #1: Then the radio button "#gender-male" should be selected
|
|
1585
|
+
* Example #2: Then the radio button "#gender-female" should not be selected
|
|
1586
|
+
* Example #3: Then the radio button ".option-1" should be selected
|
|
1041
1587
|
*
|
|
1042
1588
|
*/
|
|
1043
|
-
|
|
1044
|
-
//
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
} else {
|
|
1049
|
-
assetsFolder = path.join(__dirname, '/tests/assets/');
|
|
1050
|
-
}
|
|
1589
|
+
Then(/^(the )*radio button "([^"]*)?" should( not)* be selected$/, function (theCase, radioButton, notCase) {
|
|
1590
|
+
// Actively wait for dynamically generated radio button by polling the DOM
|
|
1591
|
+
return browser.executeAsync(function(radioSelector, shouldBeSelected, done) {
|
|
1592
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
1593
|
+
var attempts = 0;
|
|
1051
1594
|
|
|
1052
|
-
|
|
1595
|
+
var checkRadio = setInterval(function() {
|
|
1596
|
+
var element = document.querySelector(radioSelector);
|
|
1597
|
+
attempts++;
|
|
1053
1598
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1599
|
+
if (element && element.type === 'radio') {
|
|
1600
|
+
clearInterval(checkRadio);
|
|
1601
|
+
var isSelected = element.checked;
|
|
1602
|
+
done({ found: true, selected: isSelected });
|
|
1603
|
+
} else if (attempts >= maxAttempts) {
|
|
1604
|
+
clearInterval(checkRadio);
|
|
1605
|
+
done({ found: false, selected: false });
|
|
1606
|
+
}
|
|
1607
|
+
}, 500);
|
|
1608
|
+
}, [radioButton, !notCase], function(result) {
|
|
1609
|
+
if (!result || !result.value || !result.value.found) {
|
|
1610
|
+
browser.assert.fail('Radio button "' + radioButton + '" was not found in dynamically generated content');
|
|
1611
|
+
} else {
|
|
1612
|
+
if (notCase) {
|
|
1613
|
+
if (result.value.selected) {
|
|
1614
|
+
browser.assert.fail('Radio button "' + radioButton + '" should not be selected but it is');
|
|
1615
|
+
}
|
|
1616
|
+
} else {
|
|
1617
|
+
if (!result.value.selected) {
|
|
1618
|
+
browser.assert.fail('Radio button "' + radioButton + '" should be selected but it is not');
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
});
|
|
1059
1623
|
});
|
|
1060
1624
|
|
|
1061
1625
|
/**
|
|
1062
|
-
* Assert, that
|
|
1626
|
+
* Assert, that radio button with specified value in a group should or should not be selected.
|
|
1063
1627
|
*
|
|
1064
|
-
* Example: Then the "
|
|
1628
|
+
* Example #1: Then the radio button with value "male" should be selected
|
|
1629
|
+
* Example #2: Then the radio button with value "female" should not be selected
|
|
1065
1630
|
*
|
|
1066
1631
|
*/
|
|
1067
|
-
Then(/^(the )*"([^"]*)?"
|
|
1632
|
+
Then(/^(the )*radio button with value "([^"]*)?" should( not)* be selected$/, function (theCase, radioValue, notCase) {
|
|
1633
|
+
// Actively wait for dynamically generated radio button by polling the DOM
|
|
1634
|
+
return browser.executeAsync(function(value, shouldBeSelected, done) {
|
|
1635
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
1636
|
+
var attempts = 0;
|
|
1068
1637
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1638
|
+
var checkRadio = setInterval(function() {
|
|
1639
|
+
var radioButtons = document.querySelectorAll('input[type="radio"]');
|
|
1640
|
+
var element = null;
|
|
1641
|
+
|
|
1642
|
+
for (var i = 0; i < radioButtons.length; i++) {
|
|
1643
|
+
if (radioButtons[i].value === value) {
|
|
1644
|
+
element = radioButtons[i];
|
|
1645
|
+
break;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
attempts++;
|
|
1650
|
+
|
|
1651
|
+
if (element) {
|
|
1652
|
+
clearInterval(checkRadio);
|
|
1653
|
+
var isSelected = element.checked;
|
|
1654
|
+
done({ found: true, selected: isSelected });
|
|
1655
|
+
} else if (attempts >= maxAttempts) {
|
|
1656
|
+
clearInterval(checkRadio);
|
|
1657
|
+
done({ found: false, selected: false });
|
|
1658
|
+
}
|
|
1659
|
+
}, 500);
|
|
1660
|
+
}, [radioValue, !notCase], function(result) {
|
|
1661
|
+
if (!result || !result.value || !result.value.found) {
|
|
1662
|
+
browser.assert.fail('Radio button with value "' + radioValue + '" was not found in dynamically generated content');
|
|
1663
|
+
} else {
|
|
1664
|
+
if (notCase) {
|
|
1665
|
+
if (result.value.selected) {
|
|
1666
|
+
browser.assert.fail('Radio button with value "' + radioValue + '" should not be selected but it is');
|
|
1667
|
+
}
|
|
1668
|
+
} else {
|
|
1669
|
+
if (!result.value.selected) {
|
|
1670
|
+
browser.assert.fail('Radio button with value "' + radioValue + '" should be selected but it is not');
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1074
1674
|
});
|
|
1075
1675
|
});
|
|
1076
1676
|
|
|
1077
1677
|
/**
|
|
1078
|
-
*
|
|
1678
|
+
* Check, whether the radio button specified is or is not selected (using Nightwatch built-in assertion).
|
|
1079
1679
|
*
|
|
1080
|
-
* Example: Then the "#
|
|
1680
|
+
* Example #1: Then the "#gender-male" radio button is selected
|
|
1681
|
+
* Example #2: Then the "#gender-female" radio button is not selected
|
|
1081
1682
|
*
|
|
1082
1683
|
*/
|
|
1083
|
-
Then(/^(the )*"([^"]*)?"
|
|
1684
|
+
Then(/^(the )*"([^"]*)?" radio button is( not)* selected$/, function (theCase, radioButton, notCase) {
|
|
1685
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
1686
|
+
browser.pause(500);
|
|
1687
|
+
// Wait for radio button to be present (handles dynamically generated radio buttons)
|
|
1688
|
+
browser.waitForElementPresent(radioButton, 5000);
|
|
1084
1689
|
|
|
1085
|
-
|
|
1086
|
-
browser.
|
|
1087
|
-
}
|
|
1690
|
+
if (notCase) {
|
|
1691
|
+
return browser.expect.element(radioButton).to.not.be.selected;
|
|
1692
|
+
} else {
|
|
1693
|
+
return browser.expect.element(radioButton).to.be.selected;
|
|
1694
|
+
}
|
|
1088
1695
|
});
|
|
1089
1696
|
|
|
1090
1697
|
/**
|
|
1091
|
-
*
|
|
1698
|
+
* Checks, that the current page response status is or is not equal the specified code.
|
|
1092
1699
|
*
|
|
1093
|
-
* Example: Then the
|
|
1094
|
-
*
|
|
1095
|
-
*/
|
|
1096
|
-
Then(/^(the )*"([^"]*)?" checkbox should be checked$/, function (theCase, checkbox) {
|
|
1097
|
-
return browser.expect.element(checkbox).to.be.selected;
|
|
1098
|
-
});
|
|
1099
|
-
|
|
1100
|
-
/**
|
|
1101
|
-
* Assert, that checkbox with specified element is should not be checked.
|
|
1700
|
+
* Example #1: Then the response status code should be 200
|
|
1701
|
+
* Example #2: And the response status code should not be 404
|
|
1102
1702
|
*
|
|
1103
|
-
* Example: Then the "#PrivacyPolicy" checkbox should not be checked
|
|
1104
|
-
*
|
|
1105
1703
|
*/
|
|
1106
|
-
Then(/^(the )*
|
|
1107
|
-
return browser.
|
|
1704
|
+
Then(/^(the )*response status code should( not)* be (\d+)$/, function (theCase, notCase, expectedStatusCode) {
|
|
1705
|
+
return browser.url(function (currentURL) {
|
|
1706
|
+
axios.get(currentURL.value)
|
|
1707
|
+
.then(function (response) {
|
|
1708
|
+
if (notCase) {
|
|
1709
|
+
browser.assert.not.equal(response.status, expectedStatusCode);
|
|
1710
|
+
} else {
|
|
1711
|
+
browser.assert.equal(response.status, expectedStatusCode);
|
|
1712
|
+
}
|
|
1713
|
+
})
|
|
1714
|
+
.catch(function (error) {
|
|
1715
|
+
if (notCase) {
|
|
1716
|
+
browser.assert.not.equal(error.status, expectedStatusCode);
|
|
1717
|
+
} else {
|
|
1718
|
+
browser.assert.equal(error.status, expectedStatusCode);
|
|
1719
|
+
}
|
|
1720
|
+
})
|
|
1721
|
+
.finally(function () {
|
|
1722
|
+
// always executed
|
|
1723
|
+
});
|
|
1724
|
+
});
|
|
1108
1725
|
});
|
|
1109
1726
|
|
|
1110
1727
|
/**
|
|
1111
|
-
*
|
|
1728
|
+
* Checks, that page contains or does not contain text matching specified pattern.
|
|
1112
1729
|
*
|
|
1113
|
-
* Example: Then
|
|
1730
|
+
* Example #1: Then I should see text matching "^T\w+" //pattern of word start with 'T'
|
|
1731
|
+
* Example #2: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
|
|
1114
1732
|
*
|
|
1115
1733
|
*/
|
|
1116
|
-
Then(/^(
|
|
1117
|
-
|
|
1118
|
-
|
|
1734
|
+
Then(/^(I |we )*should( not)* see text matching "([^"]*)?"$/, function (pronounCase, notCase, textPattern) {
|
|
1735
|
+
// Wait for dynamically rendered content
|
|
1736
|
+
browser.pause(500);
|
|
1737
|
+
// Wait for body element to be present (handles dynamically generated content)
|
|
1738
|
+
browser.waitForElementPresent('body', 5000);
|
|
1119
1739
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1740
|
+
browser.elements('css selector', 'body', function (elements) {
|
|
1741
|
+
elements.value.forEach(function (elementsObj) {
|
|
1742
|
+
if (notCase) {
|
|
1743
|
+
return browser.assert.not.textMatches(elementsObj, textPattern);
|
|
1744
|
+
} else {
|
|
1745
|
+
return browser.assert.textMatches(elementsObj, textPattern);
|
|
1746
|
+
}
|
|
1747
|
+
});
|
|
1748
|
+
});
|
|
1128
1749
|
});
|
|
1129
1750
|
|
|
1130
1751
|
/**
|
|
1131
|
-
*
|
|
1752
|
+
* Checks, that page contains or does not contain text matching specified pattern.
|
|
1132
1753
|
*
|
|
1133
|
-
* Example: Then
|
|
1754
|
+
* Example #1: Then I should see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element
|
|
1755
|
+
* // pattern of DD/MM/YYYY or DD-MM-YYYY
|
|
1756
|
+
* Example #2: Then I should not see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element
|
|
1757
|
+
* // pattern of DD/MM/YYYY or DD-MM-YYYY
|
|
1134
1758
|
*
|
|
1135
1759
|
*/
|
|
1136
|
-
Then(/^(
|
|
1137
|
-
|
|
1138
|
-
|
|
1760
|
+
Then(/^(I |we )*should( not)* see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, notCase, textPattern, theCase, element) {
|
|
1761
|
+
// Wait for dynamic content to render (AJAX/JS)
|
|
1762
|
+
browser.pause(500);
|
|
1763
|
+
// Wait for element to be present (handles dynamically generated elements)
|
|
1764
|
+
browser.waitForElementPresent(element, 5000);
|
|
1139
1765
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
return browser.expect.element(checkbox).to.not.be.selected;
|
|
1766
|
+
if (notCase) {
|
|
1767
|
+
return browser.assert.not.textMatches(element, textPattern);
|
|
1768
|
+
} else {
|
|
1769
|
+
return this.shouldSeePattern = function (browser) {
|
|
1770
|
+
browser.assert.textMatches(element, textPattern);
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1148
1773
|
});
|
|
1149
1774
|
|
|
1150
1775
|
/**
|
|
1151
|
-
*
|
|
1776
|
+
* Checks, that current URL Path matches or does not match regular expression.
|
|
1152
1777
|
*
|
|
1153
|
-
* Example: Then the
|
|
1778
|
+
* Example #1: Then the url should match "/contact-us.html"
|
|
1779
|
+
* Example #2: Then the url should not match "/contact-us.html"
|
|
1154
1780
|
*
|
|
1155
1781
|
*/
|
|
1156
|
-
Then(/^(the )*
|
|
1157
|
-
|
|
1782
|
+
Then(/^(the )*url should( not)* match "([^"]*)?"$/, function (theCase, notCase, pattern) {
|
|
1783
|
+
// Wait for page to load and URL changes from AJAX/JS navigation
|
|
1784
|
+
browser.pause(500);
|
|
1785
|
+
// Wait for page to be present (handles dynamic navigation)
|
|
1786
|
+
browser.waitForElementPresent('body', 5000);
|
|
1787
|
+
|
|
1788
|
+
if (notCase) {
|
|
1789
|
+
return browser.assert.not.urlMatches(pattern);
|
|
1790
|
+
} else {
|
|
1791
|
+
return browser.assert.urlMatches(pattern);
|
|
1792
|
+
}
|
|
1158
1793
|
});
|
|
1159
1794
|
|
|
1795
|
+
|
|
1160
1796
|
/**
|
|
1161
|
-
*
|
|
1797
|
+
* Attaches file to field.
|
|
1162
1798
|
*
|
|
1163
|
-
* Example:
|
|
1799
|
+
* Example: When I attach the file "profileIcon.jpg" to "#profile-icon-upload"
|
|
1164
1800
|
*
|
|
1165
1801
|
*/
|
|
1166
|
-
|
|
1167
|
-
|
|
1802
|
+
When(/^(I |we )*attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronounCase, theCase, fileName, element) {
|
|
1803
|
+
// Construct local file path.
|
|
1804
|
+
let assetsFolder;
|
|
1805
|
+
if (browser.globals && browser.globals.assets_folder) {
|
|
1806
|
+
assetsFolder = browser.globals.assets_folder;
|
|
1807
|
+
} else {
|
|
1808
|
+
assetsFolder = path.join(__dirname, '/tests/assets/');
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
const localFilePath = path.resolve(assetsFolder, fileName);
|
|
1812
|
+
|
|
1813
|
+
// Wait for file input element to be present
|
|
1814
|
+
browser.waitForElementPresent(element, 5000);
|
|
1815
|
+
browser.pause(5000);
|
|
1816
|
+
browser.uploadFile(element, localFilePath);
|
|
1817
|
+
browser.pause(10000);
|
|
1818
|
+
return browser.setValue(element, fileName);
|
|
1819
|
+
|
|
1168
1820
|
});
|
|
1169
1821
|
|
|
1822
|
+
|
|
1823
|
+
|
|
1170
1824
|
/**
|
|
1171
1825
|
* Wait a specific number of seconds.
|
|
1172
1826
|
*
|
|
@@ -1253,118 +1907,57 @@ When(/^(I |we )*wait until( the)* page( is)* loaded*$/, function (pronounCase, t
|
|
|
1253
1907
|
});
|
|
1254
1908
|
|
|
1255
1909
|
/**
|
|
1256
|
-
*
|
|
1910
|
+
* Wait for AJAX requests to finish.
|
|
1911
|
+
* This step waits for active XMLHttpRequest and Fetch API requests to complete.
|
|
1257
1912
|
*
|
|
1258
|
-
* Example #1:
|
|
1913
|
+
* Example #1: When I wait for AJAX to finish
|
|
1914
|
+
* Example #2: And I wait for AJAX to finish
|
|
1915
|
+
* Example #3: When we wait for AJAX to finish
|
|
1916
|
+
* Example #4: And wait for AJAX to finish
|
|
1259
1917
|
*
|
|
1260
1918
|
*/
|
|
1261
|
-
|
|
1262
|
-
return browser.
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
browser.assert.equal(response.status, expectedStatusCode);
|
|
1266
|
-
})
|
|
1267
|
-
.catch(function (error) {
|
|
1268
|
-
browser.assert.equal(error.status, expectedStatusCode);
|
|
1269
|
-
})
|
|
1270
|
-
.finally(function () {
|
|
1271
|
-
// always executed
|
|
1272
|
-
});
|
|
1273
|
-
});
|
|
1274
|
-
});
|
|
1919
|
+
When(/^(I |we )*wait for AJAX to finish$/, function (pronounCase) {
|
|
1920
|
+
return browser.executeAsync(function(done) {
|
|
1921
|
+
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds max
|
|
1922
|
+
var attempts = 0;
|
|
1275
1923
|
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
*
|
|
1279
|
-
* Example #1: And the response status code should not be 404
|
|
1280
|
-
*
|
|
1281
|
-
*/
|
|
1282
|
-
Then(/^(the )*response status code should not be (\d+)$/, function ( theCase, expectedStatusCode) {
|
|
1283
|
-
return browser.url(function (currentURL) {
|
|
1284
|
-
axios.get(currentURL.value)
|
|
1285
|
-
.then(function (response) {
|
|
1286
|
-
browser.assert.not.equal(response.status, expectedStatusCode);
|
|
1287
|
-
})
|
|
1288
|
-
.catch(function (error) {
|
|
1289
|
-
browser.assert.not.equal(error.status, expectedStatusCode);
|
|
1290
|
-
})
|
|
1291
|
-
.finally(function () {
|
|
1292
|
-
// always executed
|
|
1293
|
-
});
|
|
1294
|
-
});
|
|
1295
|
-
});
|
|
1924
|
+
var checkAjax = setInterval(function() {
|
|
1925
|
+
attempts++;
|
|
1296
1926
|
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
*
|
|
1300
|
-
* Example: Then I should see text matching "^T\w+" //pattern of word start with 'T'
|
|
1301
|
-
*
|
|
1302
|
-
*/
|
|
1303
|
-
Then(/^(I |we )*should see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
|
|
1304
|
-
browser.elements('css selector', 'body', function (elements) {
|
|
1305
|
-
elements.value.forEach(function (elementsObj) {
|
|
1306
|
-
return browser.assert.textMatches(elementsObj, textPattern);
|
|
1307
|
-
});
|
|
1308
|
-
});
|
|
1309
|
-
});
|
|
1927
|
+
// Check for active XMLHttpRequest requests
|
|
1928
|
+
var activeXHR = window.XMLHttpRequest && window.XMLHttpRequest.active || 0;
|
|
1310
1929
|
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
*
|
|
1314
|
-
* Example #1: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
|
|
1315
|
-
*
|
|
1316
|
-
*/
|
|
1317
|
-
Then(/^(I |we )*should not see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
|
|
1318
|
-
browser.elements('css selector', 'body', function (elements) {
|
|
1319
|
-
elements.value.forEach(function (elementsObj) {
|
|
1320
|
-
return browser.assert.not.textMatches(elementsObj, textPattern);
|
|
1321
|
-
});
|
|
1322
|
-
});
|
|
1323
|
-
});
|
|
1930
|
+
// Check for active fetch requests (tracked via monkey-patching)
|
|
1931
|
+
var activeFetch = window.__activeFetchCount || 0;
|
|
1324
1932
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
*
|
|
1328
|
-
* Example #1: Then I should see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element
|
|
1329
|
-
* // pattern of DD/MM/YYYY or DD-MM-YYYY
|
|
1330
|
-
*
|
|
1331
|
-
*/
|
|
1332
|
-
Then(/^(I |we )*should see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, theCase, element) {
|
|
1333
|
-
return this.shouldSeePattern = function (browser) {
|
|
1334
|
-
browser.assert.textMatches(element, textPattern);
|
|
1335
|
-
};
|
|
1336
|
-
});
|
|
1933
|
+
// Check if document is still loading
|
|
1934
|
+
var documentLoading = document.readyState !== 'complete';
|
|
1337
1935
|
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1936
|
+
if (activeXHR === 0 && activeFetch === 0 && !documentLoading) {
|
|
1937
|
+
clearInterval(checkAjax);
|
|
1938
|
+
done({ finished: true, attempts: attempts });
|
|
1939
|
+
} else if (attempts >= maxAttempts) {
|
|
1940
|
+
clearInterval(checkAjax);
|
|
1941
|
+
done({
|
|
1942
|
+
finished: false,
|
|
1943
|
+
attempts: attempts,
|
|
1944
|
+
activeXHR: activeXHR,
|
|
1945
|
+
activeFetch: activeFetch,
|
|
1946
|
+
documentLoading: documentLoading
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1949
|
+
}, 500);
|
|
1950
|
+
}, [], function(result) {
|
|
1951
|
+
if (!result || !result.value || !result.value.finished) {
|
|
1952
|
+
var debugInfo = result && result.value ?
|
|
1953
|
+
` (XHR: ${result.value.activeXHR}, Fetch: ${result.value.activeFetch}, DocLoading: ${result.value.documentLoading})` : '';
|
|
1954
|
+
console.warn('AJAX requests did not finish within timeout period' + debugInfo);
|
|
1955
|
+
// Don't fail the test, just log a warning
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1347
1958
|
});
|
|
1348
1959
|
|
|
1349
|
-
/**
|
|
1350
|
-
* Checks, that current URL Path matches regular expression.
|
|
1351
|
-
*
|
|
1352
|
-
* Example: Then the url should match "/contact-us.html"
|
|
1353
|
-
*
|
|
1354
|
-
*/
|
|
1355
|
-
Then(/^(the )*url should match "([^"]*)?"$/, function (theCase, pattern) {
|
|
1356
|
-
return browser.assert.urlMatches(pattern);
|
|
1357
|
-
});
|
|
1358
1960
|
|
|
1359
|
-
/**
|
|
1360
|
-
* Checks, that current URL Path matches regular expression.
|
|
1361
|
-
*
|
|
1362
|
-
* Example: Then the url should not match "/contact-us.html"
|
|
1363
|
-
*
|
|
1364
|
-
*/
|
|
1365
|
-
Then(/^(the )*url should not match "([^"]*)?"$/, function (theCase, pattern) {
|
|
1366
|
-
return browser.assert.not.urlMatches(pattern);
|
|
1367
|
-
});
|
|
1368
1961
|
|
|
1369
1962
|
/**
|
|
1370
1963
|
* Scrolls down the page by a custom number of pixels specified by the user.
|
|
@@ -1466,29 +2059,32 @@ When(/^(I scroll|we scroll|scrolling)? to top of "([^"]*)"$/, function(pronounCa
|
|
|
1466
2059
|
if (!selector || selector.trim() === '') {
|
|
1467
2060
|
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1468
2061
|
}
|
|
1469
|
-
|
|
2062
|
+
|
|
1470
2063
|
// Validate selector format (basic check)
|
|
1471
2064
|
if (selector.includes('"') || selector.includes("'")) {
|
|
1472
2065
|
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1473
2066
|
}
|
|
1474
|
-
|
|
2067
|
+
|
|
1475
2068
|
try {
|
|
2069
|
+
// Wait for element to be present (allows dynamic elements to load)
|
|
2070
|
+
browser.waitForElementPresent(selector, 5000);
|
|
2071
|
+
|
|
1476
2072
|
// Check if element exists before scrolling
|
|
1477
2073
|
const elementExists = browser.executeScript(`
|
|
1478
2074
|
return document.querySelector("${selector}") !== null;
|
|
1479
2075
|
`);
|
|
1480
|
-
|
|
2076
|
+
|
|
1481
2077
|
if (!elementExists) {
|
|
1482
2078
|
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1483
2079
|
}
|
|
1484
|
-
|
|
2080
|
+
|
|
1485
2081
|
browser.executeScript(`
|
|
1486
2082
|
const element = document.querySelector("${selector}");
|
|
1487
2083
|
if (element) {
|
|
1488
2084
|
element.scrollTop = 0;
|
|
1489
2085
|
}
|
|
1490
2086
|
`);
|
|
1491
|
-
|
|
2087
|
+
|
|
1492
2088
|
return browser.pause(2000);
|
|
1493
2089
|
} catch (error) {
|
|
1494
2090
|
throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
|
|
@@ -1507,29 +2103,32 @@ When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, function(pronou
|
|
|
1507
2103
|
if (!selector || selector.trim() === '') {
|
|
1508
2104
|
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1509
2105
|
}
|
|
1510
|
-
|
|
2106
|
+
|
|
1511
2107
|
// Validate selector format (basic check)
|
|
1512
2108
|
if (selector.includes('"') || selector.includes("'")) {
|
|
1513
2109
|
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1514
2110
|
}
|
|
1515
|
-
|
|
2111
|
+
|
|
1516
2112
|
try {
|
|
2113
|
+
// Wait for element to be present (allows dynamic elements to load)
|
|
2114
|
+
browser.waitForElementPresent(selector, 5000);
|
|
2115
|
+
|
|
1517
2116
|
// Check if element exists before scrolling
|
|
1518
2117
|
const elementExists = browser.executeScript(`
|
|
1519
2118
|
return document.querySelector("${selector}") !== null;
|
|
1520
2119
|
`);
|
|
1521
|
-
|
|
2120
|
+
|
|
1522
2121
|
if (!elementExists) {
|
|
1523
2122
|
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1524
2123
|
}
|
|
1525
|
-
|
|
2124
|
+
|
|
1526
2125
|
browser.executeScript(`
|
|
1527
2126
|
const element = document.querySelector("${selector}");
|
|
1528
2127
|
if (element) {
|
|
1529
2128
|
element.scrollTop = element.scrollHeight;
|
|
1530
2129
|
}
|
|
1531
2130
|
`);
|
|
1532
|
-
|
|
2131
|
+
|
|
1533
2132
|
return browser.pause(2000);
|
|
1534
2133
|
} catch (error) {
|
|
1535
2134
|
throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
|
|
@@ -1636,29 +2235,32 @@ When(/^(I scroll|we scroll|scrolling)? to start of "([^"]*)"$/, function(pronoun
|
|
|
1636
2235
|
if (!selector || selector.trim() === '') {
|
|
1637
2236
|
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1638
2237
|
}
|
|
1639
|
-
|
|
2238
|
+
|
|
1640
2239
|
// Validate selector format (basic check)
|
|
1641
2240
|
if (selector.includes('"') || selector.includes("'")) {
|
|
1642
2241
|
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1643
2242
|
}
|
|
1644
|
-
|
|
2243
|
+
|
|
1645
2244
|
try {
|
|
2245
|
+
// Wait for element to be present (allows dynamic elements to load)
|
|
2246
|
+
browser.waitForElementPresent(selector, 5000);
|
|
2247
|
+
|
|
1646
2248
|
// Check if element exists before scrolling
|
|
1647
2249
|
const elementExists = browser.executeScript(`
|
|
1648
2250
|
return document.querySelector("${selector}") !== null;
|
|
1649
2251
|
`);
|
|
1650
|
-
|
|
2252
|
+
|
|
1651
2253
|
if (!elementExists) {
|
|
1652
2254
|
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1653
2255
|
}
|
|
1654
|
-
|
|
2256
|
+
|
|
1655
2257
|
browser.executeScript(`
|
|
1656
2258
|
const element = document.querySelector("${selector}");
|
|
1657
2259
|
if (element) {
|
|
1658
2260
|
element.scrollTop = 0;
|
|
1659
2261
|
}
|
|
1660
2262
|
`);
|
|
1661
|
-
|
|
2263
|
+
|
|
1662
2264
|
return browser.pause(2000);
|
|
1663
2265
|
} catch (error) {
|
|
1664
2266
|
throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
|
|
@@ -1677,31 +2279,395 @@ When(/^(I scroll|we scroll|scrolling)? to end of "([^"]*)"$/, function(pronounCa
|
|
|
1677
2279
|
if (!selector || selector.trim() === '') {
|
|
1678
2280
|
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
1679
2281
|
}
|
|
1680
|
-
|
|
2282
|
+
|
|
1681
2283
|
// Validate selector format (basic check)
|
|
1682
2284
|
if (selector.includes('"') || selector.includes("'")) {
|
|
1683
2285
|
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
1684
2286
|
}
|
|
1685
|
-
|
|
2287
|
+
|
|
1686
2288
|
try {
|
|
2289
|
+
// Wait for element to be present (allows dynamic elements to load)
|
|
2290
|
+
browser.waitForElementPresent(selector, 5000);
|
|
2291
|
+
|
|
1687
2292
|
// Check if element exists before scrolling
|
|
1688
2293
|
const elementExists = browser.executeScript(`
|
|
1689
2294
|
return document.querySelector("${selector}") !== null;
|
|
1690
2295
|
`);
|
|
1691
|
-
|
|
2296
|
+
|
|
1692
2297
|
if (!elementExists) {
|
|
1693
2298
|
throw new Error(`Element with selector "${selector}" not found.`);
|
|
1694
2299
|
}
|
|
1695
|
-
|
|
2300
|
+
|
|
1696
2301
|
browser.executeScript(`
|
|
1697
2302
|
const element = document.querySelector("${selector}");
|
|
1698
2303
|
if (element) {
|
|
1699
2304
|
element.scrollTop = element.scrollWidth;
|
|
1700
2305
|
}
|
|
1701
2306
|
`);
|
|
1702
|
-
|
|
2307
|
+
|
|
1703
2308
|
return browser.pause(2000);
|
|
1704
2309
|
} catch (error) {
|
|
1705
2310
|
throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
|
|
1706
2311
|
}
|
|
1707
2312
|
});
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* Assert that a modal dialog is visible or not visible on the page.
|
|
2316
|
+
*
|
|
2317
|
+
* Example #1: Then I should see a modal
|
|
2318
|
+
* Example #2: Then I should see the modal
|
|
2319
|
+
* Example #3: Then we should see a modal dialog
|
|
2320
|
+
* Example #4: Then I should not see a modal
|
|
2321
|
+
* Example #5: Then I should not see the modal dialog
|
|
2322
|
+
*
|
|
2323
|
+
*/
|
|
2324
|
+
Then(/^(I |we )*should( not)* see (a |the )*modal( dialog)*$/, function (pronounCase, notCase, aTheCase, dialogCase) {
|
|
2325
|
+
// Common selectors for modals
|
|
2326
|
+
const modalSelectors = [
|
|
2327
|
+
'.modal:not([style*="display: none"])',
|
|
2328
|
+
'.modal.show',
|
|
2329
|
+
'.modal.in',
|
|
2330
|
+
'[role="dialog"]',
|
|
2331
|
+
'.dialog:not([style*="display: none"])',
|
|
2332
|
+
'.popup:not([style*="display: none"])',
|
|
2333
|
+
'.overlay:not([style*="display: none"])'
|
|
2334
|
+
];
|
|
2335
|
+
|
|
2336
|
+
return browser.execute(function(selectors) {
|
|
2337
|
+
for (let selector of selectors) {
|
|
2338
|
+
const elements = document.querySelectorAll(selector);
|
|
2339
|
+
for (let element of elements) {
|
|
2340
|
+
const style = window.getComputedStyle(element);
|
|
2341
|
+
if (style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0') {
|
|
2342
|
+
return true;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
return false;
|
|
2347
|
+
}, [modalSelectors], function(result) {
|
|
2348
|
+
if (notCase) {
|
|
2349
|
+
if (result.value) {
|
|
2350
|
+
throw new Error('Modal dialog is visible, but it should not be.');
|
|
2351
|
+
}
|
|
2352
|
+
} else {
|
|
2353
|
+
if (!result.value) {
|
|
2354
|
+
throw new Error('Modal dialog is not visible, but it should be.');
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
});
|
|
2359
|
+
|
|
2360
|
+
/**
|
|
2361
|
+
* Assert that a modal dialog with specific title is visible or not visible.
|
|
2362
|
+
*
|
|
2363
|
+
* Example #1: Then I should see a modal with title "Confirm Action"
|
|
2364
|
+
* Example #2: Then I should see the modal with title "Welcome"
|
|
2365
|
+
* Example #3: Then we should see a modal with title "Welcome Message"
|
|
2366
|
+
* Example #4: Then I should not see a modal with title "Error"
|
|
2367
|
+
* Example #5: Then I should not see the modal with title "Validation Error"
|
|
2368
|
+
*
|
|
2369
|
+
*/
|
|
2370
|
+
Then(/^(I |we )*should( not)* see (a |the )*modal with title "([^"]*)?"$/, function (pronounCase, notCase, aTheCase, title) {
|
|
2371
|
+
return browser.execute(function(searchTitle) {
|
|
2372
|
+
const modals = document.querySelectorAll('[role="dialog"], .modal, .dialog, .popup');
|
|
2373
|
+
|
|
2374
|
+
for (let modal of modals) {
|
|
2375
|
+
const style = window.getComputedStyle(modal);
|
|
2376
|
+
|
|
2377
|
+
// Only check visible modals
|
|
2378
|
+
if (style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0') {
|
|
2379
|
+
const titleAttr = modal.getAttribute('title') || modal.getAttribute('aria-label') || '';
|
|
2380
|
+
const titleElement = modal.querySelector('.modal-title, .dialog-title, h1, h2, h3');
|
|
2381
|
+
const titleText = titleElement ? (titleElement.textContent || titleElement.innerText || '').trim() : '';
|
|
2382
|
+
|
|
2383
|
+
if (titleAttr.includes(searchTitle) || titleText.includes(searchTitle) || titleText === searchTitle) {
|
|
2384
|
+
return true;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
return false;
|
|
2389
|
+
}, [title], function(result) {
|
|
2390
|
+
if (notCase) {
|
|
2391
|
+
if (result.value) {
|
|
2392
|
+
throw new Error(`Modal with title "${title}" is visible, but it should not be.`);
|
|
2393
|
+
}
|
|
2394
|
+
} else {
|
|
2395
|
+
if (!result.value) {
|
|
2396
|
+
throw new Error(`Modal with title "${title}" is not visible or not found.`);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
});
|
|
2401
|
+
|
|
2402
|
+
/**
|
|
2403
|
+
* Assert that a specific modal dialog by ID/class is visible or not visible.
|
|
2404
|
+
*
|
|
2405
|
+
* Example #1: Then I should see a "confirmation-modal" modal
|
|
2406
|
+
* Example #2: Then I should see the "#delete-modal" modal
|
|
2407
|
+
* Example #3: Then we should see a "settings-modal" modal
|
|
2408
|
+
* Example #4: Then I should not see a "error-modal" modal
|
|
2409
|
+
* Example #5: Then I should not see the "#success-modal" modal
|
|
2410
|
+
*
|
|
2411
|
+
*/
|
|
2412
|
+
Then(/^(I |we )*should( not)* see (a |the )*"([^"]*)?" modal$/, function (pronounCase, notCase, aTheCase, identifier) {
|
|
2413
|
+
return browser.execute(function(searchId) {
|
|
2414
|
+
// Find modal by ID/class selector
|
|
2415
|
+
let modal = null;
|
|
2416
|
+
if (searchId.startsWith('#') || searchId.startsWith('.')) {
|
|
2417
|
+
modal = document.querySelector(searchId);
|
|
2418
|
+
} else {
|
|
2419
|
+
// Search by various attributes
|
|
2420
|
+
modal = document.querySelector(`#${searchId}`) ||
|
|
2421
|
+
document.querySelector(`.${searchId}`) ||
|
|
2422
|
+
document.querySelector(`[data-modal="${searchId}"]`);
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
if (!modal) {
|
|
2426
|
+
return false;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// Check if modal is visible
|
|
2430
|
+
const style = window.getComputedStyle(modal);
|
|
2431
|
+
return style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0';
|
|
2432
|
+
}, [identifier], function(result) {
|
|
2433
|
+
if (notCase) {
|
|
2434
|
+
if (result.value) {
|
|
2435
|
+
throw new Error(`Modal "${identifier}" is visible, but it should not be.`);
|
|
2436
|
+
}
|
|
2437
|
+
} else {
|
|
2438
|
+
if (!result.value) {
|
|
2439
|
+
throw new Error(`Modal "${identifier}" is not visible or not found.`);
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
});
|
|
2443
|
+
});
|
|
2444
|
+
|
|
2445
|
+
/**
|
|
2446
|
+
* Assert that modal contains specific text.
|
|
2447
|
+
*
|
|
2448
|
+
* Example #1: Then the modal should contain "Are you sure?"
|
|
2449
|
+
* Example #2: Then I should see "Delete this item" in the modal
|
|
2450
|
+
* Example #3: Then we should see "Confirmation required" in the modal dialog
|
|
2451
|
+
* Example #4: Then the modal should not contain "Error occurred"
|
|
2452
|
+
*
|
|
2453
|
+
*/
|
|
2454
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* modal( dialog)*$/, function (pronounCase, notCase, expectedText, theCase, dialogCase) {
|
|
2455
|
+
return browser.execute(function(text) {
|
|
2456
|
+
const modalSelectors = [
|
|
2457
|
+
'.modal:not([style*="display: none"])',
|
|
2458
|
+
'.modal.show',
|
|
2459
|
+
'.modal.in',
|
|
2460
|
+
'[role="dialog"]',
|
|
2461
|
+
'.dialog:not([style*="display: none"])',
|
|
2462
|
+
'.popup:not([style*="display: none"])'
|
|
2463
|
+
];
|
|
2464
|
+
|
|
2465
|
+
for (let selector of modalSelectors) {
|
|
2466
|
+
const elements = document.querySelectorAll(selector);
|
|
2467
|
+
for (let element of elements) {
|
|
2468
|
+
const style = window.getComputedStyle(element);
|
|
2469
|
+
if (style.display !== 'none' && style.visibility !== 'hidden') {
|
|
2470
|
+
const modalText = element.textContent || element.innerText || '';
|
|
2471
|
+
if (modalText.includes(text)) {
|
|
2472
|
+
return true;
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
return false;
|
|
2478
|
+
}, [expectedText], function(result) {
|
|
2479
|
+
if (notCase) {
|
|
2480
|
+
if (result.value) {
|
|
2481
|
+
throw new Error(`Found "${expectedText}" in modal, but it should not be there.`);
|
|
2482
|
+
}
|
|
2483
|
+
} else {
|
|
2484
|
+
if (!result.value) {
|
|
2485
|
+
throw new Error(`Could not find "${expectedText}" in modal.`);
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
});
|
|
2489
|
+
});
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* Click a button or link within a modal dialog.
|
|
2493
|
+
*
|
|
2494
|
+
* Example #1: When I click "Confirm" in the modal
|
|
2495
|
+
* Example #2: When I click "Cancel" in the modal dialog
|
|
2496
|
+
* Example #3: When we click "OK" button in the modal
|
|
2497
|
+
* Example #4: And I click "Close" in the modal
|
|
2498
|
+
*
|
|
2499
|
+
*/
|
|
2500
|
+
When(/^(I |we )*click "([^"]*)?"( button)* in( the)* modal( dialog)*$/, function (pronounCase, buttonText, buttonCase, theCase, dialogCase) {
|
|
2501
|
+
return browser.execute(function(btnText) {
|
|
2502
|
+
const modalSelectors = [
|
|
2503
|
+
'.modal:not([style*="display: none"])',
|
|
2504
|
+
'.modal.show',
|
|
2505
|
+
'.modal.in',
|
|
2506
|
+
'[role="dialog"]',
|
|
2507
|
+
'.dialog:not([style*="display: none"])',
|
|
2508
|
+
'.popup:not([style*="display: none"])'
|
|
2509
|
+
];
|
|
2510
|
+
|
|
2511
|
+
for (let selector of modalSelectors) {
|
|
2512
|
+
const modals = document.querySelectorAll(selector);
|
|
2513
|
+
for (let modal of modals) {
|
|
2514
|
+
const style = window.getComputedStyle(modal);
|
|
2515
|
+
if (style.display !== 'none' && style.visibility !== 'hidden') {
|
|
2516
|
+
// Find clickable elements within modal
|
|
2517
|
+
const clickables = modal.querySelectorAll('button, a, [role="button"], input[type="button"], input[type="submit"], .btn');
|
|
2518
|
+
|
|
2519
|
+
for (let element of clickables) {
|
|
2520
|
+
const text = (element.textContent || element.innerText || element.value || '').trim();
|
|
2521
|
+
if (text === btnText || text.includes(btnText)) {
|
|
2522
|
+
element.click();
|
|
2523
|
+
return { success: true };
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
// If not found in obvious clickables, search by text
|
|
2528
|
+
const allElements = modal.querySelectorAll('*');
|
|
2529
|
+
for (let element of allElements) {
|
|
2530
|
+
const text = (element.textContent || element.innerText || '').trim();
|
|
2531
|
+
if (text === btnText && element.offsetParent !== null) {
|
|
2532
|
+
element.click();
|
|
2533
|
+
return { success: true };
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
return { success: false, error: `Could not find "${btnText}" button in modal` };
|
|
2540
|
+
}, [buttonText], function(result) {
|
|
2541
|
+
if (!result.value.success) {
|
|
2542
|
+
throw new Error(result.value.error || `Could not click "${buttonText}" in modal`);
|
|
2543
|
+
}
|
|
2544
|
+
});
|
|
2545
|
+
});
|
|
2546
|
+
|
|
2547
|
+
/**
|
|
2548
|
+
* Close a modal dialog by clicking the close button or overlay.
|
|
2549
|
+
*
|
|
2550
|
+
* Example #1: When I close the modal
|
|
2551
|
+
* Example #2: When I dismiss the modal dialog
|
|
2552
|
+
* Example #3: When we close the modal
|
|
2553
|
+
* Example #4: And I dismiss the modal
|
|
2554
|
+
*
|
|
2555
|
+
*/
|
|
2556
|
+
When(/^(I |we )*(close|dismiss)( the)* modal( dialog)*$/, function (pronounCase, closeOrDismiss, theCase, dialogCase) {
|
|
2557
|
+
return browser.execute(function() {
|
|
2558
|
+
const modalSelectors = [
|
|
2559
|
+
'.modal:not([style*="display: none"])',
|
|
2560
|
+
'.modal.show',
|
|
2561
|
+
'.modal.in',
|
|
2562
|
+
'[role="dialog"]',
|
|
2563
|
+
'.dialog:not([style*="display: none"])',
|
|
2564
|
+
'.popup:not([style*="display: none"])'
|
|
2565
|
+
];
|
|
2566
|
+
|
|
2567
|
+
for (let selector of modalSelectors) {
|
|
2568
|
+
const modals = document.querySelectorAll(selector);
|
|
2569
|
+
for (let modal of modals) {
|
|
2570
|
+
const style = window.getComputedStyle(modal);
|
|
2571
|
+
if (style.display !== 'none' && style.visibility !== 'hidden') {
|
|
2572
|
+
// Try to find close button
|
|
2573
|
+
const closeButtons = modal.querySelectorAll(
|
|
2574
|
+
'.close, .modal-close, [data-dismiss="modal"], [aria-label="Close"], .btn-close, button[class*="close"]'
|
|
2575
|
+
);
|
|
2576
|
+
|
|
2577
|
+
for (let btn of closeButtons) {
|
|
2578
|
+
if (window.getComputedStyle(btn).display !== 'none') {
|
|
2579
|
+
btn.click();
|
|
2580
|
+
return { success: true, method: 'close button' };
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
// Try ESC key
|
|
2585
|
+
const escEvent = new KeyboardEvent('keydown', {
|
|
2586
|
+
key: 'Escape',
|
|
2587
|
+
code: 'Escape',
|
|
2588
|
+
keyCode: 27,
|
|
2589
|
+
which: 27,
|
|
2590
|
+
bubbles: true
|
|
2591
|
+
});
|
|
2592
|
+
modal.dispatchEvent(escEvent);
|
|
2593
|
+
|
|
2594
|
+
// Check if modal has data-dismiss or onclick handler
|
|
2595
|
+
if (modal.hasAttribute('data-dismiss')) {
|
|
2596
|
+
modal.click();
|
|
2597
|
+
return { success: true, method: 'modal click' };
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
return { success: true, method: 'escape key' };
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
return { success: false, error: 'No visible modal found to close' };
|
|
2605
|
+
}, [], function(result) {
|
|
2606
|
+
if (!result.value.success) {
|
|
2607
|
+
throw new Error(result.value.error || 'Could not close modal');
|
|
2608
|
+
}
|
|
2609
|
+
});
|
|
2610
|
+
});
|
|
2611
|
+
|
|
2612
|
+
/**
|
|
2613
|
+
* Wait for modal to appear or disappear.
|
|
2614
|
+
*
|
|
2615
|
+
* Example #1: When I wait for the modal to appear
|
|
2616
|
+
* Example #2: When I wait for the modal to disappear
|
|
2617
|
+
* Example #3: When we wait for modal to appear
|
|
2618
|
+
* Example #4: And I wait for the modal dialog to disappear
|
|
2619
|
+
*
|
|
2620
|
+
*/
|
|
2621
|
+
When(/^(I |we )*wait for( the)* modal( dialog)* to (appear|disappear)$/, function (pronounCase, theCase, dialogCase, appearOrDisappear) {
|
|
2622
|
+
const shouldAppear = appearOrDisappear === 'appear';
|
|
2623
|
+
const maxWaitTime = 10000; // 10 seconds
|
|
2624
|
+
const pollInterval = 500; // 500ms
|
|
2625
|
+
|
|
2626
|
+
return browser.executeAsync(function(shouldAppear, maxWaitTime, pollInterval, done) {
|
|
2627
|
+
const modalSelectors = [
|
|
2628
|
+
'.modal:not([style*="display: none"])',
|
|
2629
|
+
'.modal.show',
|
|
2630
|
+
'.modal.in',
|
|
2631
|
+
'[role="dialog"]',
|
|
2632
|
+
'.dialog:not([style*="display: none"])',
|
|
2633
|
+
'.popup:not([style*="display: none"])'
|
|
2634
|
+
];
|
|
2635
|
+
|
|
2636
|
+
function checkModal() {
|
|
2637
|
+
for (let selector of modalSelectors) {
|
|
2638
|
+
const elements = document.querySelectorAll(selector);
|
|
2639
|
+
for (let element of elements) {
|
|
2640
|
+
const style = window.getComputedStyle(element);
|
|
2641
|
+
if (style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0') {
|
|
2642
|
+
return true;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
return false;
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
let elapsed = 0;
|
|
2650
|
+
const interval = setInterval(function() {
|
|
2651
|
+
const modalVisible = checkModal();
|
|
2652
|
+
|
|
2653
|
+
if ((shouldAppear && modalVisible) || (!shouldAppear && !modalVisible)) {
|
|
2654
|
+
clearInterval(interval);
|
|
2655
|
+
done({ success: true });
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
elapsed += pollInterval;
|
|
2660
|
+
if (elapsed >= maxWaitTime) {
|
|
2661
|
+
clearInterval(interval);
|
|
2662
|
+
done({
|
|
2663
|
+
success: false,
|
|
2664
|
+
error: `Timeout: Modal did not ${shouldAppear ? 'appear' : 'disappear'} within ${maxWaitTime}ms`
|
|
2665
|
+
});
|
|
2666
|
+
}
|
|
2667
|
+
}, pollInterval);
|
|
2668
|
+
}, [shouldAppear, maxWaitTime, pollInterval], function(result) {
|
|
2669
|
+
if (!result.value.success) {
|
|
2670
|
+
throw new Error(result.value.error || `Modal did not ${appearOrDisappear}`);
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
});
|