webship-js 1.0.44 → 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.
Files changed (81) hide show
  1. package/.eslintrc.json +0 -0
  2. package/examples/about-us.html +0 -0
  3. package/examples/ajax-wait-examples.html +147 -0
  4. package/examples/contact-us.html +0 -0
  5. package/examples/dynamic-examples.html +499 -0
  6. package/examples/example-api.json +0 -0
  7. package/examples/existing-page.html +0 -0
  8. package/examples/index.html +1 -0
  9. package/examples/test--then--i-should--see-text-in-element.html +0 -0
  10. package/examples/test--then--i-should--see-text-matching-pattern.html +0 -0
  11. package/examples/test--then--i-should-see-text-in-table-row.html +0 -0
  12. package/examples/test--then--the-checkbox-checked.html +0 -0
  13. package/examples/test--then--the-element-should_not-contain-cssproperty.html +0 -0
  14. package/examples/test--then--the-link-should-contain.html +0 -0
  15. package/examples/test--when--i-attach-file-to-feild.html +0 -0
  16. package/examples/test--when--i-check-uncheck-checkbox.html +0 -0
  17. package/examples/test--when--i-click-link.html +0 -0
  18. package/examples/test--when--i-click-text-in-table-row.html +0 -0
  19. package/examples/test--when--i-press-button.html +0 -0
  20. package/examples/test--when--i-reload-page.html +0 -0
  21. package/examples/test--when--i-scroll-functionality.html +0 -0
  22. package/examples/test--when--i-scroll-left-right-functionality.html +0 -0
  23. package/examples/test--when--i-select-option-from-dropdownlist.html +0 -0
  24. package/examples/test--when--i-select-radio-button.html +95 -0
  25. package/examples/test--when-i-wait-max-of-time.html +0 -0
  26. package/examples/test--when-i-wait-page-until-is-loaded.html +0 -0
  27. package/examples/test--when-i-wait-specific-time.html +0 -0
  28. package/examples/test-acceptable-url-path.html +0 -0
  29. package/nightwatch.conf.js +1 -1
  30. package/package.json +1 -1
  31. package/tests/features/ajax-wait-examples.feature +24 -0
  32. package/tests/features/api-step-definitions-individual.feature +0 -0
  33. package/tests/features/complete-api-testing-examples.feature +0 -0
  34. package/tests/features/dynamic-content-examples.feature +156 -0
  35. package/tests/features/modal-advanced-example.feature +54 -0
  36. package/tests/features/modal-basic-example.feature +42 -0
  37. package/tests/features/modal-error-handling-example.feature +37 -0
  38. package/tests/features/test--given--i-am-on-homepage.feature +0 -0
  39. package/tests/features/test--then--i-should--not--see-text-in-element.feature +0 -0
  40. package/tests/features/test--then--i-should--see-text-in-element-by-attr.feature +0 -0
  41. package/tests/features/test--then--i-should--see-text-in-element.feature +0 -0
  42. package/tests/features/test--then--i-should--see-text-matching-pattern-in-element.feature +0 -0
  43. package/tests/features/test--then--i-should--see-text-matching-pattern.feature +0 -0
  44. package/tests/features/test--then--i-should-be-on-page.feature +0 -0
  45. package/tests/features/test--then--i-should-be-on-the-homepage.feature +0 -0
  46. package/tests/features/test--then--i-should-not-see-an-element-by-attr.feature +0 -0
  47. package/tests/features/test--then--i-should-not-see-an-element.feature +0 -0
  48. package/tests/features/test--then--i-should-see-an-element-by-attr.feature +0 -0
  49. package/tests/features/test--then--i-should-see-an-element.feature +0 -0
  50. package/tests/features/test--then--i-should-see-text-in-table-row.feature +0 -0
  51. package/tests/features/test--then--the-checkbox-is-checked.feature +0 -0
  52. package/tests/features/test--then--the-checkbox-should-be-checked.feature +0 -0
  53. package/tests/features/test--then--the-element-should-contain-cssproperty.feature +0 -0
  54. package/tests/features/test--then--the-element-should-not-contain-cssproperty.feature +0 -0
  55. package/tests/features/test--then--the-field-should-contain-value.feature +0 -0
  56. package/tests/features/test--then--the-response-should-contain.feature +0 -0
  57. package/tests/features/test--then--the-response-status-code-should-be.feature +0 -0
  58. package/tests/features/test--then--the-url-should-match.feature +0 -0
  59. package/tests/features/test--then-the-link-should-contain-by-attribute.feature +0 -0
  60. package/tests/features/test--then-the-link-should-contain.feature +0 -0
  61. package/tests/features/test--when--i-attach-file-to-feild.feature +0 -0
  62. package/tests/features/test--when--i-check-checkbox.feature +0 -0
  63. package/tests/features/test--when--i-click-link-by-attribute.feature +0 -0
  64. package/tests/features/test--when--i-click-link.feature +0 -0
  65. package/tests/features/test--when--i-click-text-in-table-row.feature +0 -0
  66. package/tests/features/test--when--i-fill-in-by-attr.feature +0 -0
  67. package/tests/features/test--when--i-fill-in-table-by-attr.feature +0 -0
  68. package/tests/features/test--when--i-fill-in.feature +0 -0
  69. package/tests/features/test--when--i-go-to-homepage.feature +0 -0
  70. package/tests/features/test--when--i-move-forward-backward-one-page.feature +0 -0
  71. package/tests/features/test--when--i-press-button-by-attribute.feature +0 -0
  72. package/tests/features/test--when--i-press-button.feature +0 -0
  73. package/tests/features/test--when--i-reload-page.feature +0 -0
  74. package/tests/features/test--when--i-scroll-left-right.feature +0 -0
  75. package/tests/features/test--when--i-scroll.feature +0 -0
  76. package/tests/features/test--when--i-select-option-from-dropdownlist.feature +0 -0
  77. package/tests/features/test--when--i-select-radio-button.feature +37 -0
  78. package/tests/features/test--when--i-wait-page-is-loaded.feature +0 -0
  79. package/tests/features/test--when--i-wait-time.feature +0 -0
  80. package/tests/step-definitions/webship-api.js +27 -15
  81. package/tests/step-definitions/webship.js +1475 -500
@@ -14,8 +14,8 @@ const path = require('path');
14
14
  * @param {string} key
15
15
  */
16
16
  function safePause(key) {
17
- const time = (global.browser?.globals?.minimum_wait_time?.[key]) || 0;
18
- if (time > 0 && global.browser?.pause) {
17
+ const time = (global.browser && global.browser.globals && global.browser.globals.minimum_wait_time && global.browser.globals.minimum_wait_time[key]) || 0;
18
+ if (time > 0 && global.browser && global.browser.pause) {
19
19
  global.browser.pause(time);
20
20
  }
21
21
  }
@@ -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
- return browser.waitForElementPresent('body', defaultTime);
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
- let defaultTime = 3000;
77
- if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
78
- defaultTime = browser.globals.minimum_wait_time.page;
79
- }
80
- return browser.waitForElementPresent('body', defaultTime);
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
- return browser.waitForElementPresent('body', defaultTime);
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
- return browser.waitForElementPresent('body', defaultTime);
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
- browser.assert.not.textContains("html", expectedText);
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
- browser.click("[value='" + element +"']");
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
- return browser.click(selector);
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
- return browser.click("link text", item);
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.click(selector);
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,101 +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
- // First, find all table elements on the page
269
- return browser.elements('css selector', 'table', function (tableResult) {
270
- if (tableResult.value.length === 0) {
271
- throw new Error('No tables found on the page');
272
- }
273
405
 
274
- // Search through each table for the row containing the identifier
275
- let foundElement = false;
276
-
277
- tableResult.value.forEach(function (table, tableIndex) {
278
- if (foundElement) return; // Skip if already found
279
-
280
- // Get all rows in this table
281
- browser.elements('css selector', 'tr', table, function (rowResult) {
282
- if (rowResult.value.length === 0) return;
283
-
284
- rowResult.value.forEach(function (row, rowIndex) {
285
- if (foundElement) return; // Skip if already found
286
-
287
- // Check if this row contains the identifier text
288
- browser.getText(row, function (rowText) {
289
- if (rowText.value && rowText.value.includes(rowIdentifier)) {
290
-
291
- // Found the correct row, now look for the clickable text within this row
292
- browser.elements('css selector', '*', row, function (cellElements) {
293
- cellElements.value.forEach(function (element) {
294
- if (foundElement) return; // Skip if already found
295
-
296
- browser.getText(element, function (elementText) {
297
- if (elementText.value && elementText.value.trim() === clickText) {
298
- // Found the target text, click it
299
- browser.click(element);
300
- foundElement = true;
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;
434
+ }
435
+ }
436
+
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 });
301
453
  return;
302
454
  }
303
- });
304
-
305
- // Also check if element is a link or button with the text
306
- browser.getAttribute(element, 'tagName', function (tagName) {
307
- if (foundElement) return;
308
-
309
- if (tagName.value && (tagName.value.toLowerCase() === 'a' || tagName.value.toLowerCase() === 'button')) {
310
- browser.getText(element, function (linkText) {
311
- if (linkText.value && linkText.value.trim() === clickText) {
312
- browser.click(element);
313
- foundElement = true;
314
- return;
315
- }
316
- });
317
- }
318
- });
319
- });
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
+ }
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) + '...'
320
474
  });
475
+ return;
321
476
  }
322
- });
477
+ }
478
+ }
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(', ')
323
484
  });
324
- });
325
- });
326
-
327
- // Add a small pause to ensure the operation completes
328
- browser.pause(1000);
329
-
330
- // If we didn't find the element, throw an error
331
- if (!foundElement) {
332
- throw new Error(`Could not find "${clickText}" in the "${rowIdentifier}" row. Please verify the table structure and text content.`);
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);
494
+ }, [rowIdentifier, clickText], function(result) {
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);
333
498
  }
334
499
  });
335
500
  });
336
501
 
337
502
  /**
338
- * 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.
339
504
  * This step finds a table, locates a row containing the identifier text, then verifies the target text is visible within that row.
340
505
  *
341
506
  * Example #1: Then I should see "Active" in the "John Smith" row
342
- * 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
343
508
  * Example #3: Then we should see "Processing" in the "Order #12345" row
344
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
345
513
  *
346
514
  */
347
- Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, expectedText, theCase, rowIdentifier) {
348
-
515
+ Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, notCase, expectedText, theCase, rowIdentifier) {
516
+
349
517
  return browser.execute(function(rowId, expectedTxt) {
350
518
  // Find all tables
351
519
  const tables = document.querySelectorAll('table');
352
520
  if (tables.length === 0) {
353
521
  throw new Error('No tables found on the page');
354
522
  }
355
-
523
+
356
524
  // Search through each table for the row containing the identifier
357
525
  for (let table of tables) {
358
526
  const rows = table.querySelectorAll('tr');
@@ -368,46 +536,14 @@ Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pron
368
536
  }
369
537
  return false; // Text not found
370
538
  }, [rowIdentifier, expectedText], function(result) {
371
- if (!result.value) {
372
- throw new Error(`Could not find "${expectedText}" in the "${rowIdentifier}" row. Please verify the table structure and text content.`);
373
- }
374
- });
375
- });
376
-
377
- /**
378
- * Asserts that specific text is NOT visible within a table row that contains a specified identifier text.
379
- *
380
- * Example #1: Then I should not see "Admin" in the "Jane Doe" row
381
- * Example #2: Then I should not see "Out of Stock" in the "Product A" row
382
- * Example #3: And I should not see "Inactive" in the "john.smith@example.com" row
383
- *
384
- */
385
- Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, expectedText, theCase, rowIdentifier) {
386
-
387
- return browser.execute(function(rowId, expectedTxt) {
388
- // Find all tables
389
- const tables = document.querySelectorAll('table');
390
- if (tables.length === 0) {
391
- throw new Error('No tables found on the page');
392
- }
393
-
394
- // Search through each table for the row containing the identifier
395
- for (let table of tables) {
396
- const rows = table.querySelectorAll('tr');
397
- for (let row of rows) {
398
- const rowText = row.textContent || row.innerText;
399
- if (rowText.includes(rowId)) {
400
- // Found the correct row, now check if it contains the expected text
401
- if (rowText.includes(expectedTxt)) {
402
- return true; // Found the text (this is bad for "should not see")
403
- }
404
- }
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.`);
405
546
  }
406
- }
407
- return false; // Text not found (this is good for "should not see")
408
- }, [rowIdentifier, expectedText], function(result) {
409
- if (result.value) {
410
- throw new Error(`Found "${expectedText}" in the "${rowIdentifier}" row, but it should not be there.`);
411
547
  }
412
548
  });
413
549
  });
@@ -432,8 +568,12 @@ When(/^(I |we )*reload( the)*( page)*$/, function (pronounCase, theCase, pageCas
432
568
  *
433
569
  */
434
570
  When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?"$/, function (pronounCase, field, value) {
571
+ // Wait for dynamic content to render (AJAX/JS)
572
+ browser.pause(500);
435
573
  const elementField = browser.element.findByText(field, { exact: true });
436
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);
437
577
  return browser.setValue('#' + eleAttribute.value, value);
438
578
  });
439
579
  });
@@ -465,6 +605,7 @@ When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attr
465
605
  selector = '[' + attr + '="' + attrValue + '"]';
466
606
  }
467
607
 
608
+ browser.waitForElementPresent(selector, 5000);
468
609
  return browser.setValue(selector, txtValue);
469
610
 
470
611
  });
@@ -476,8 +617,12 @@ When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attr
476
617
  *
477
618
  */
478
619
  When(/^(I |we )*fill in "([^"]*)?" with:$/, function (pronounCase, field) {
620
+ // Wait for dynamic content to render (AJAX/JS)
621
+ browser.pause(500);
479
622
  const elementField = browser.element.findByText(field, { exact: true });
480
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);
481
626
  return browser.setValue('#' + eleAttribute.value, '');
482
627
  });
483
628
  });
@@ -509,6 +654,7 @@ When(/^(I |we )*fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr
509
654
  selector = '[' + attr + '="' + attrValue + '"]';
510
655
  }
511
656
 
657
+ browser.waitForElementPresent(selector, 5000);
512
658
  return browser.setValue(selector, '');
513
659
  });
514
660
 
@@ -520,8 +666,12 @@ When(/^(I |we )*fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr
520
666
  *
521
667
  */
522
668
  When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?"$/, function (pronounCase, value, field) {
669
+ // Wait for dynamic content to render (AJAX/JS)
670
+ browser.pause(500);
523
671
  const elementField = browser.element.findByText(field, { exact: true });
524
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);
525
675
  return browser.setValue('#' + eleAttribute.value, value);
526
676
  });
527
677
  });
@@ -553,7 +703,29 @@ When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attri
553
703
  selector = '[' + attr + '="' + attrValue + '"]';
554
704
  }
555
705
 
556
- return browser.setValue(selector, txtValue);
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
+ });
557
729
 
558
730
  });
559
731
 
@@ -567,15 +739,22 @@ When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attri
567
739
 
568
740
  When(/^(I |we )*fill in( the)* following:$/, function (pronounCase, theCase, table) {
569
741
 
742
+ // Wait for dynamic content to render (AJAX/JS)
743
+ browser.pause(500);
744
+
570
745
  var elementField = browser.element.findByText(table.rawTable[0][0], { exact: true });
571
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);
572
749
  browser.setValue('#' + eleAttribute.value, table.rawTable[0][1]);
573
750
  });
574
-
751
+
575
752
  table.rows().forEach(row => {
576
753
 
577
754
  elementField = browser.element.findByText(row[0], { exact: true });
578
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);
579
758
  browser.setValue('#' + eleAttribute2.value, row[1]);
580
759
  });
581
760
  });
@@ -597,7 +776,7 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
597
776
 
598
777
  var hasASpace = table.rawTable[0][0].indexOf(' ');
599
778
  var selector = '';
600
-
779
+
601
780
  if((table.rawTable[0][0].startsWith('#') || table.rawTable[0][0].startsWith('.')) && hasASpace == -1){
602
781
  selector = table.rawTable[0][0];
603
782
  }
@@ -611,9 +790,10 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
611
790
  selector = '[' + attr + '="' + table.rawTable[0][0] + '"]';
612
791
  }
613
792
 
793
+ browser.waitForElementPresent(selector, 5000);
614
794
  browser.setValue(selector, table.rawTable[0][1]);
615
795
 
616
-
796
+
617
797
  table.rows().forEach(row => {
618
798
 
619
799
  hasASpace = row[0].indexOf(' ');
@@ -623,7 +803,7 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
623
803
  selector = row[0];
624
804
  }
625
805
  else if (!attr && hasASpace == -1){
626
-
806
+
627
807
  selector = row[0] + ',#' + row[0] + ',.' + row[0] + ',[name=' + row[0] + "]," + '[value="' + row[0] + '"],[placeholder="' + row[0] + '"]';
628
808
  }
629
809
  else if (!attr && hasASpace > -1){
@@ -633,6 +813,7 @@ When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|att
633
813
  selector = '[' + attr + '="' + row[0] + '"]';
634
814
  }
635
815
 
816
+ browser.waitForElementPresent(selector, 5000);
636
817
  browser.setValue(selector, row[1]);
637
818
 
638
819
  });
@@ -661,6 +842,12 @@ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, opti
661
842
  selector = browser.element.findByText(selectList, { exact: true });
662
843
  }
663
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
+
664
851
  let optionValue = '';
665
852
  const result = option.toLowerCase();
666
853
 
@@ -670,7 +857,7 @@ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, opti
670
857
  else{
671
858
  optionValue = browser.element.findByText(option, { exact: true });
672
859
  }
673
-
860
+
674
861
  return browser.click(selector).click(optionValue).click(selector);
675
862
  });
676
863
 
@@ -682,7 +869,51 @@ When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, opti
682
869
  *
683
870
  */
684
871
  When(/^(I |we )*check "([^"]*)?"$/, function (pronounCase, item) {
685
- browser.checkItem(item);
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
+ });
686
917
  });
687
918
 
688
919
  /**
@@ -693,11 +924,137 @@ When(/^(I |we )*check "([^"]*)?"$/, function (pronounCase, item) {
693
924
  *
694
925
  */
695
926
  When(/^(I |we )*uncheck "([^"]*)?"$/, function (pronounCase, item) {
696
- browser.uncheckItem(item);
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
+ });
697
1054
  });
698
1055
 
699
1056
  /**
700
- * Verify, that current page is the homepage.
1057
+ * Verify, that current page is or is not the homepage.
701
1058
  *
702
1059
  * Example #1: Then I should be on homepage
703
1060
  * Example #2: And I should be on the homepage
@@ -707,30 +1064,25 @@ When(/^(I |we )*uncheck "([^"]*)?"$/, function (pronounCase, item) {
707
1064
  * Example #6: And we should be on homepage
708
1065
  * Example #7: Then should be on frontpage
709
1066
  * Example #8: And we should be on the homepage
710
- *
711
- */
712
- Then(/^(I |we )*should be on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
713
- return browser.assert.urlMatches(browser.launch_url);
714
- });
715
-
716
- /**
717
- * Verify, that current page is the homepage.
718
- *
719
- * Example #1: Then I should not be on homepage
720
- * Example #2: And I should not be on the homepage
721
- * Example #3: Then I should not be on frontpage
722
- * Example #4: Then we should not be on homepage
723
- * Example #5: Then should not be on the homepage
724
- * Example #6: And we should not be on frontpage
725
- * Example #7: And we should not be on the homepage
726
- *
727
- */
728
- Then(/^(I |we )*should not be on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
729
- 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
+ }
730
1082
  });
731
1083
 
732
1084
  /**
733
- * Verify, that current page path is equal to specified path.
1085
+ * Verify, that current page path is equal or not equal to specified path.
734
1086
  *
735
1087
  * Example #1: Then I should be on "/"
736
1088
  * Example #2: And I should be on "/user/login"
@@ -740,27 +1092,22 @@ Then(/^(I |we )*should not be on( the)* (homepage|frontpage)$/, function (pronou
740
1092
  * Example #6: And we should be on "https://google.com"
741
1093
  * Example #7: Then should be on the "/user/reset" page
742
1094
  * Example #8: And we should be on "https://x.com"
743
- *
744
- */
745
- Then(/^(I |we )*should be on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
746
- return browser.assert.urlContains(url);
747
- });
748
-
749
- /**
750
- * Verify, that current page path dose not equal to specified path.
751
- *
752
- * Example #1: Then I should not be on "/"
753
- * Example #2: And I should not be on "/user/login"
754
- * Example #3: And I should not be on "https://un.org"
755
- * Example #4: Then we should not be on the "/" page
756
- * Example #5: And we should not be on "/user/login"
757
- * Example #6: Then we should not be on "https://google.com"
758
- * Example #7: And should not be on "/user/reset"
759
- * Example #8: And we should not be on the "https://x.com" page
760
- *
761
- */
762
- Then(/^(I |we )*should not be on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
763
- 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
+ }
764
1111
  });
765
1112
 
766
1113
  /**
@@ -770,7 +1117,11 @@ Then(/^(I |we )*should not be on( the)* "([^"]*)?"( page)*$/, function (pronounC
770
1117
  *
771
1118
  */
772
1119
  Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, function (theCase, element, url) {
1120
+ // Wait for dynamic content to render (AJAX/JS)
1121
+ browser.pause(500);
773
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);
774
1125
  return browser.assert.attributeContains(elementField, 'href', url);
775
1126
  });
776
1127
 
@@ -784,6 +1135,9 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, function (theCase, el
784
1135
  */
785
1136
  Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (theCase, attrValue, url, itsCase, attr, attrCase) {
786
1137
 
1138
+ // Wait for dynamic content to render (AJAX/JS)
1139
+ browser.pause(500);
1140
+
787
1141
  const hasASpace = attrValue.indexOf(' ');
788
1142
  var selector = '';
789
1143
 
@@ -800,62 +1154,92 @@ Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")*
800
1154
  selector = '[' + attr + '="' + attrValue + '"]';
801
1155
  }
802
1156
 
1157
+ // Wait for link to be present (handles dynamically generated links)
1158
+ browser.waitForElementPresent(selector, 5000);
803
1159
  return browser.assert.attributeContains(selector, 'href', url);
804
1160
  });
805
1161
 
806
1162
  /**
807
- * Checks, that HTML response contains specific text.
1163
+ * Checks, that HTML response contains or does not contain specific text.
808
1164
  *
809
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?"
810
1167
  *
811
1168
  */
812
- Then(/^(the )*response should contain "([^"]*)?"$/, function (theCase, expectedText) {
813
- return this.shouldSee = function (browser) {
814
- browser.assert.textContains("html", expectedText);
815
- };
816
- });
817
-
818
- /**
819
- * Checks, that HTML response dose not contains specific text.
820
- *
821
- * Example #1: Then the response should not contain "Welcome visitor, How can I help you?"
822
- *
823
- */
824
- Then(/^(the )*response should not contain "([^"]*)?"$/, function (theCase, expectedText) {
1169
+ Then(/^(the )*response should( not)* contain "([^"]*)?"$/, function (theCase, notCase, expectedText) {
825
1170
  return this.shouldSee = function (browser) {
826
- browser.assert.not.textContains("html", expectedText);
1171
+ if (notCase) {
1172
+ browser.assert.not.textContains("html", expectedText);
1173
+ } else {
1174
+ browser.assert.textContains("html", expectedText);
1175
+ }
827
1176
  };
828
1177
  });
829
1178
 
830
1179
  /**
831
- * 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.
832
1181
  *
833
1182
  * Example #1: Then I should see "John Smith" in the "Username" element
834
1183
  * Example #2: Then I should not see "Joe Smith" in the "Username" element
835
- *
1184
+ *
836
1185
  */
837
- Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText, theCase , element) {
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
+
838
1190
  const elementField = browser.element.findByText(element, { exact: true });
839
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
+
840
1195
  return this.shouldSee = function (browser) {
841
- browser.assert.textContains('#' + eleAttribute.value, expectedText);
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
+ }
842
1221
  };
843
1222
  });
844
1223
  });
845
1224
 
846
1225
  /**
847
- * 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
848
1232
  *
849
- * Example: Then I should see "John Smith" in the "uname" element by its "id" attr
850
- * Example: Then I should see "1234" in the "pwordcss" element by attr
851
- *
852
1233
  */
853
- 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) {
854
1235
 
855
1236
  const hasASpace = attrValue.indexOf(' ');
856
1237
 
857
1238
  var selector = '';
858
- if (!attr && hasASpace == -1){
1239
+ if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
1240
+ selector = attrValue;
1241
+ }
1242
+ else if (!attr && hasASpace == -1){
859
1243
  selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
860
1244
  }
861
1245
  else if (!attr && hasASpace > -1){
@@ -865,35 +1249,77 @@ Then(/^(I |we )*should see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "(
865
1249
  selector = '[' + attr + '="' + attrValue + '"]';
866
1250
  }
867
1251
 
868
- return this.shouldSee = function (browser) {
869
- browser.assert.textContains(selector, expectedText);
870
- };
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
+ });
871
1285
  });
872
1286
 
873
1287
  /**
874
- * Assert, that input text does not contain a specific value to be by its label.
1288
+ * Assert, that element exists or does not exist on current page by its label.
875
1289
  *
876
- * Example: Then I should not see "Joe Smith" in the "Username" element
1290
+ * Example #1: Then I should see a "Username" element
1291
+ * Example #2: Then I should not see a "Username" element
877
1292
  *
878
1293
  */
879
- Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, expectedText, theCase, element) {
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);
880
1297
 
881
- const elementField = browser.element.findByText(element, { exact: true });
882
- browser.getAttribute(elementField, 'for', function (eleAttribute) {
883
- return this.shouldSee = function (browser) {
884
- browser.assert.not.textContains('#' + eleAttribute.value, expectedText);
885
- };
886
- });
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
+ }
887
1311
  });
888
1312
 
889
1313
  /**
890
- * Assert, that input text contains a specific value by its attributes.
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
891
1320
  *
892
- * Example: Then I should not see "John Smith" in the "uname" element by its "id" attr
893
- * Example: Then I should not see "1234" in the "pwordcss" element by attr
894
- *
895
1321
  */
896
- Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, expectedText, theCase, attrValue, itsCase, attr, attrCase) {
1322
+ Then(/^(I |we )*should( not)* see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, notCase, aAnCase, attrValue, itsCase, attr, attrCase) {
897
1323
 
898
1324
  const hasASpace = attrValue.indexOf(' ');
899
1325
 
@@ -908,256 +1334,493 @@ Then(/^(I |we )*should not see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*
908
1334
  selector = '[' + attr + '="' + attrValue + '"]';
909
1335
  }
910
1336
 
911
- return this.shouldSee = function (browser) {
912
- browser.assert.not.textContains(selector, expectedText);
913
- };
914
- });
1337
+ // Wait for dynamic content
1338
+ browser.pause(500);
915
1339
 
916
- /**
917
- * Assert, that element exists on current page by its label.
918
- *
919
- * Example: Then I should see a "Username" element
920
- *
921
- */
922
- Then(/^(I |we )*should see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
923
- const elementField = browser.element.findByText(element, { exact: true });
924
- browser.getAttribute(elementField, 'for', function (eleAttribute) {
925
- return browser.verify.visible('#' + eleAttribute.value);
926
- });
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
+ }
927
1347
  });
928
1348
 
1349
+
929
1350
  /**
930
- * Assert, that element exists on the current page by its attribute.
1351
+ * Assert, that element contains or does not contain a specific CSS style.
1352
+ *
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;"
931
1357
  *
932
- * Example: Then I should see a "uname" element by its "id" attr
933
- * Example: Then I should see a "pwordcss" element by attr
934
- *
935
1358
  */
936
- Then(/^(I |we )*should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
1359
+ Then(/^(the )*"([^"]*)?" element should( not)* contain "([^"]*)?"$/, function (theCase, selector, notCase, elementCss) {
937
1360
 
938
- const hasASpace = attrValue.indexOf(' ');
1361
+ elementCss = elementCss.replace(";", '');
1362
+ const cssPropertyArr = elementCss.split(":");
939
1363
 
940
- var selector = '';
941
- if (!attr && hasASpace == -1){
942
- selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
943
- }
944
- else if (!attr && hasASpace > -1){
945
- selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
946
- }
947
- else {
948
- selector = '[' + attr + '="' + attrValue + '"]';
949
- }
1364
+ const cssProperty = cssPropertyArr[0].trim();
1365
+ const propertyVal = cssPropertyArr[1].trim();
950
1366
 
951
- return browser.verify.visible(selector);
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
+ }
1402
+ });
952
1403
  });
953
1404
 
954
1405
  /**
955
- * Assert, that element exists on current page by its label.
1406
+ * Assert, that field contains or does not contain a specific text.
956
1407
  *
957
- * Example: Then I should not see a "Username" element
1408
+ * Example #1: Then the "Username" field should contain "John Smith"
1409
+ * Example #2: Then the "#username" field should not contain "John Smith"
958
1410
  *
959
1411
  */
960
- Then(/^(I |we )*should not see (a|an) "([^"]*)?" element$/, function (pronounCase, aAnCase, element) {
961
- browser.assert.not.textContains("html", element);
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);
1415
+
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
+ });
1431
+ }
962
1432
  });
963
1433
 
964
1434
  /**
965
- * Assert, that element exists on current page by its attributes.
1435
+ * Assert, that checkbox with specified element is or is not checked.
966
1436
  *
967
- * Example: Then I should not see an "emailId" element by its "id" attr
968
- * Example: And I should not see a "countryCss" element by attr
1437
+ * Example #1: Then the "#PrivacyPolicy" checkbox should be checked
1438
+ * Example #2: Then the "#PrivacyPolicy" checkbox should not be checked
969
1439
  *
970
1440
  */
971
- Then(/^(I |we )*should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, aAnCase, attrValue, itsCase, attr, attrCase) {
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;
972
1446
 
973
- const hasASpace = attrValue.indexOf(' ');
1447
+ var checkCheckbox = setInterval(function() {
1448
+ var element = document.querySelector(checkboxSelector);
1449
+ attempts++;
974
1450
 
975
- var selector = '';
976
- if (!attr && hasASpace == -1){
977
- selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
978
- }
979
- else if (!attr && hasASpace > -1){
980
- selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
981
- }
982
- else {
983
- selector = '[' + attr + '="' + attrValue + '"]';
984
- }
985
-
986
- return browser.expect.element(selector).to.not.be.present;
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
+ });
987
1475
  });
988
1476
 
989
1477
  /**
990
- * Assert, that element contains a specific CSS style.
1478
+ * Check, whether the checkbox specified is or is not checked.
991
1479
  *
992
- * Example: Then the "body" element should contain "color:white;"
1480
+ * Example #1: Then the "#rememberMe" checkbox is checked
1481
+ * Example #2: Then the "#rememberMe" checkbox is not checked
993
1482
  *
994
1483
  */
995
- Then(/^(the )*"([^"]*)?" element should contain "([^"]*)?"$/, function (theCase ,selector, elementCss) {
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);
996
1489
 
997
- elementCss = elementCss.replace(";", '');
998
- const cssPropertyArr = elementCss.split(":");
999
-
1000
- const cssProperty = cssPropertyArr[0].trim();
1001
- const propertyVal = cssPropertyArr[1].trim();
1002
-
1003
- this.checkCss = function (browser) {
1004
- browser.assert.cssProperty(selector, cssProperty, propertyVal);
1005
- };
1490
+ if (notCase) {
1491
+ return browser.expect.element(checkbox).to.not.be.selected;
1492
+ } else {
1493
+ return browser.expect.element(checkbox).to.be.selected;
1494
+ }
1006
1495
  });
1007
1496
 
1008
1497
  /**
1009
- * Assert, that element contains a specific CSS style.
1498
+ * Assert, that checkbox with specified element should or should not be checked.
1499
+ *
1500
+ * Example #1: Then the checkbox "#PrivacyPolicy" should be checked
1501
+ * Example #2: Then the checkbox "#PrivacyPolicy" should not be checked
1010
1502
  *
1011
- * Example #1: Then the "body" element should not contain "color:white;"
1012
- * Example #2: Then the "#uname" element should not contain "border:solid 5px red;"
1013
- * Example #3: Then the "pword" element should not contain "font-size: 26px;"
1014
1503
  */
1015
- Then(/^(the )*"([^"]*)?" element should not contain "([^"]*)?"$/, function (theCase, selector, elementCss) {
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;
1016
1508
 
1017
- elementCss = elementCss.replace(";", '');
1018
- const cssPropertyArr = elementCss.split(":");
1509
+ var checkCheckbox = setInterval(function() {
1510
+ var element = document.querySelector(checkboxSelector);
1511
+ attempts++;
1019
1512
 
1020
- const cssProperty = cssPropertyArr[0].trim();
1021
- const propertyVal = cssPropertyArr[1].trim();
1022
-
1023
- this.checkCss = function (browser) {
1024
- browser.assert.not.cssProperty(selector, cssProperty, propertyVal);
1025
- };
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
+ });
1026
1537
  });
1027
1538
 
1028
1539
  /**
1029
- * Attaches file to field.
1540
+ * Assert, that checkbox with specified element is or is not checked.
1030
1541
  *
1031
- * Example: When I attach the file "profileIcon.jpg" to "#profile-icon-upload"
1542
+ * Example #1: Then the checkbox "#rememberMe" is checked
1543
+ * Example #2: Then the checkbox "#rememberMe" is not checked
1032
1544
  *
1033
1545
  */
1034
- When(/^(I |we )*attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronounCase, theCase, fileName, element) {
1035
- // Construct local file path.
1036
- let assetsFolder;
1037
- if (browser.globals && browser.globals.assets_folder) {
1038
- assetsFolder = browser.globals.assets_folder;
1039
- } else {
1040
- assetsFolder = path.join(__dirname, '/tests/assets/');
1041
- }
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;
1042
1550
 
1043
- const localFilePath = path.resolve(assetsFolder, fileName);
1551
+ var checkCheckbox = setInterval(function() {
1552
+ var element = document.querySelector(checkboxSelector);
1553
+ attempts++;
1044
1554
 
1045
- browser.pause(5000);
1046
- browser.uploadFile(element, localFilePath);
1047
- browser.pause(10000);
1048
- return browser.setValue(element, fileName);
1049
-
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
+ });
1050
1579
  });
1051
1580
 
1052
1581
  /**
1053
- * Assert, that field contain a specific text.
1582
+ * Assert, that radio button with specified selector should or should not be selected.
1054
1583
  *
1055
- * Example: Then the "Username" field should contain "John Smith"
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
1056
1587
  *
1057
1588
  */
1058
- Then(/^(the )*"([^"]*)?" field should contain "([^"]*)?"$/, function (theCase, field, expectedText) {
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;
1059
1594
 
1060
- const elementField = browser.element.findByText(field, { exact: true });
1061
- browser.getAttribute(elementField, 'for', function (eleAttribute) {
1062
- return this.shouldSee = function (browser) {
1063
- browser.assert.textContains('#' + eleAttribute.value, expectedText);
1064
- };
1595
+ var checkRadio = setInterval(function() {
1596
+ var element = document.querySelector(radioSelector);
1597
+ attempts++;
1598
+
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
+ }
1065
1622
  });
1066
1623
  });
1067
1624
 
1068
1625
  /**
1069
- * Assert, that field does not contain a specific text.
1626
+ * Assert, that radio button with specified value in a group should or should not be selected.
1070
1627
  *
1071
- * Example: Then the "#username" field should not contain "John Smith"
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
1072
1630
  *
1073
1631
  */
1074
- Then(/^(the )*"([^"]*)?" field should not contain "([^"]*)?"$/, function (theCase, field, expectedText) {
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;
1075
1637
 
1076
- return this.shouldSee = function (browser) {
1077
- browser.assert.not.textContains(field, expectedText);
1078
- };
1079
- });
1638
+ var checkRadio = setInterval(function() {
1639
+ var radioButtons = document.querySelectorAll('input[type="radio"]');
1640
+ var element = null;
1080
1641
 
1081
- /**
1082
- * Assert, that checkbox with specified element is should be checked.
1083
- *
1084
- * Example: Then the "#PrivacyPolicy" checkbox should be checked
1085
- *
1086
- */
1087
- Then(/^(the )*"([^"]*)?" checkbox should be checked$/, function (theCase, checkbox) {
1088
- return browser.expect.element(checkbox).to.be.selected;
1089
- });
1642
+ for (var i = 0; i < radioButtons.length; i++) {
1643
+ if (radioButtons[i].value === value) {
1644
+ element = radioButtons[i];
1645
+ break;
1646
+ }
1647
+ }
1090
1648
 
1091
- /**
1092
- * Assert, that checkbox with specified element is should not be checked.
1093
- *
1094
- * Example: Then the "#PrivacyPolicy" checkbox should not be checked
1095
- *
1096
- */
1097
- Then(/^(the )*"([^"]*)?" checkbox should not be checked$/, function (theCase, checkbox) {
1098
- return browser.expect.element(checkbox).to.not.be.selected;
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
+ }
1674
+ });
1099
1675
  });
1100
1676
 
1101
1677
  /**
1102
- * Check, whether the checkbox specified is checked.
1678
+ * Check, whether the radio button specified is or is not selected (using Nightwatch built-in assertion).
1103
1679
  *
1104
- * Example: Then the "#rememberMe" checkbox is checked
1680
+ * Example #1: Then the "#gender-male" radio button is selected
1681
+ * Example #2: Then the "#gender-female" radio button is not selected
1105
1682
  *
1106
1683
  */
1107
- Then(/^(the )*"([^"]*)?" checkbox is checked$/, function (theCase, checkbox) {
1108
- return browser.expect.element(checkbox).to.be.selected;
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);
1689
+
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
+ }
1109
1695
  });
1110
1696
 
1111
1697
  /**
1112
- * Check, whether the checkbox specified is not checked.
1698
+ * Checks, that the current page response status is or is not equal the specified code.
1113
1699
  *
1114
- * Example: Then the "#rememberMe" checkbox is not checked
1700
+ * Example #1: Then the response status code should be 200
1701
+ * Example #2: And the response status code should not be 404
1115
1702
  *
1116
1703
  */
1117
- Then(/^(the )*"([^"]*)?" checkbox is not checked$/, function (theCase, checkbox) {
1118
- return browser.expect.element(checkbox).to.not.be.selected;
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
+ });
1119
1725
  });
1120
1726
 
1121
1727
  /**
1122
- * Assert, that checkbox with specified element should be checked.
1728
+ * Checks, that page contains or does not contain text matching specified pattern.
1123
1729
  *
1124
- * Example: Then the checkbox "#PrivacyPolicy" should be checked
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'
1125
1732
  *
1126
1733
  */
1127
- Then(/^(the )*checkbox "([^"]*)?" should be checked$/, function (theCase, checkbox) {
1128
- return browser.expect.element(checkbox).to.be.selected;
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);
1739
+
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
+ });
1129
1749
  });
1130
1750
 
1131
1751
  /**
1132
- * Assert, that checkbox with specified element should not be checked.
1752
+ * Checks, that page contains or does not contain text matching specified pattern.
1133
1753
  *
1134
- * Example: Then the checkbox "#PrivacyPolicy" should not be checked
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
1135
1758
  *
1136
1759
  */
1137
- Then(/^(the )*checkbox "([^"]*)?" should not be checked$/, function (theCase, checkbox) {
1138
- return browser.expect.element(checkbox).to.not.be.selected;
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);
1765
+
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
+ }
1139
1773
  });
1140
1774
 
1141
1775
  /**
1142
- * Assert, that checkbox with specified element is checked.
1776
+ * Checks, that current URL Path matches or does not match regular expression.
1143
1777
  *
1144
- * Example: Then the checkbox "#rememberMe" is checked
1778
+ * Example #1: Then the url should match "/contact-us.html"
1779
+ * Example #2: Then the url should not match "/contact-us.html"
1145
1780
  *
1146
1781
  */
1147
- Then(/^(the )*checkbox "([^"]*)?" is checked$/, function (theCase, checkbox) {
1148
- return browser.expect.element(checkbox).to.be.selected;
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
+ }
1149
1793
  });
1150
1794
 
1795
+
1151
1796
  /**
1152
- * Assert, that checkbox with specified element is not checked.
1797
+ * Attaches file to field.
1153
1798
  *
1154
- * Example: Then the checkbox "#rememberMe" is not checked
1799
+ * Example: When I attach the file "profileIcon.jpg" to "#profile-icon-upload"
1155
1800
  *
1156
1801
  */
1157
- Then(/^(the )*checkbox "([^"]*)?" is not checked$/, function (theCase, checkbox) {
1158
- return browser.expect.element(checkbox).to.not.be.selected;
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
+
1159
1820
  });
1160
1821
 
1822
+
1823
+
1161
1824
  /**
1162
1825
  * Wait a specific number of seconds.
1163
1826
  *
@@ -1244,118 +1907,57 @@ When(/^(I |we )*wait until( the)* page( is)* loaded*$/, function (pronounCase, t
1244
1907
  });
1245
1908
 
1246
1909
  /**
1247
- * Checks, that the current page response status is equal the specified code.
1910
+ * Wait for AJAX requests to finish.
1911
+ * This step waits for active XMLHttpRequest and Fetch API requests to complete.
1248
1912
  *
1249
- * Example #1: Then the response status code should be 200
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
1250
1917
  *
1251
1918
  */
1252
- Then(/^(the )*response status code should be (\d+)$/, function (theCase, expectedStatusCode) {
1253
- return browser.url(function (currentURL) {
1254
- axios.get(currentURL.value)
1255
- .then(function (response) {
1256
- browser.assert.equal(response.status, expectedStatusCode);
1257
- })
1258
- .catch(function (error) {
1259
- browser.assert.equal(error.status, expectedStatusCode);
1260
- })
1261
- .finally(function () {
1262
- // always executed
1263
- });
1264
- });
1265
- });
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;
1266
1923
 
1267
- /**
1268
- * Checks, that the current page response status is not equal the specified code.
1269
- *
1270
- * Example #1: And the response status code should not be 404
1271
- *
1272
- */
1273
- Then(/^(the )*response status code should not be (\d+)$/, function ( theCase, expectedStatusCode) {
1274
- return browser.url(function (currentURL) {
1275
- axios.get(currentURL.value)
1276
- .then(function (response) {
1277
- browser.assert.not.equal(response.status, expectedStatusCode);
1278
- })
1279
- .catch(function (error) {
1280
- browser.assert.not.equal(error.status, expectedStatusCode);
1281
- })
1282
- .finally(function () {
1283
- // always executed
1284
- });
1285
- });
1286
- });
1924
+ var checkAjax = setInterval(function() {
1925
+ attempts++;
1287
1926
 
1288
- /**
1289
- * Checks, that page contains text matching specified pattern.
1290
- *
1291
- * Example: Then I should see text matching "^T\w+" //pattern of word start with 'T'
1292
- *
1293
- */
1294
- Then(/^(I |we )*should see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
1295
- browser.elements('css selector', 'body', function (elements) {
1296
- elements.value.forEach(function (elementsObj) {
1297
- return browser.assert.textMatches(elementsObj, textPattern);
1298
- });
1299
- });
1300
- });
1927
+ // Check for active XMLHttpRequest requests
1928
+ var activeXHR = window.XMLHttpRequest && window.XMLHttpRequest.active || 0;
1301
1929
 
1302
- /**
1303
- * Checks, that page not contains text matching specified pattern.
1304
- *
1305
- * Example #1: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
1306
- *
1307
- */
1308
- Then(/^(I |we )*should not see text matching "([^"]*)?"$/, function (pronounCase, textPattern) {
1309
- browser.elements('css selector', 'body', function (elements) {
1310
- elements.value.forEach(function (elementsObj) {
1311
- return browser.assert.not.textMatches(elementsObj, textPattern);
1312
- });
1313
- });
1314
- });
1930
+ // Check for active fetch requests (tracked via monkey-patching)
1931
+ var activeFetch = window.__activeFetchCount || 0;
1315
1932
 
1316
- /**
1317
- * Checks, that page contains text matching specified pattern.
1318
- *
1319
- * 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
1320
- * // pattern of DD/MM/YYYY or DD-MM-YYYY
1321
- *
1322
- */
1323
- Then(/^(I |we )*should see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, theCase, element) {
1324
- return this.shouldSeePattern = function (browser) {
1325
- browser.assert.textMatches(element, textPattern);
1326
- };
1327
- });
1933
+ // Check if document is still loading
1934
+ var documentLoading = document.readyState !== 'complete';
1328
1935
 
1329
- /**
1330
- * Checks, that page dose not contain text matching specified pattern.
1331
- *
1332
- * Example #1: 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
1333
- * // pattern of DD/MM/YYYY or DD-MM-YYYY
1334
- *
1335
- */
1336
- Then(/^(I |we )*should not see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, textPattern, theCase, element) {
1337
- return browser.assert.not.textMatches(element, textPattern);
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
+ });
1338
1958
  });
1339
1959
 
1340
- /**
1341
- * Checks, that current URL Path matches regular expression.
1342
- *
1343
- * Example: Then the url should match "/contact-us.html"
1344
- *
1345
- */
1346
- Then(/^(the )*url should match "([^"]*)?"$/, function (theCase, pattern) {
1347
- return browser.assert.urlMatches(pattern);
1348
- });
1349
1960
 
1350
- /**
1351
- * Checks, that current URL Path matches regular expression.
1352
- *
1353
- * Example: Then the url should not match "/contact-us.html"
1354
- *
1355
- */
1356
- Then(/^(the )*url should not match "([^"]*)?"$/, function (theCase, pattern) {
1357
- return browser.assert.not.urlMatches(pattern);
1358
- });
1359
1961
 
1360
1962
  /**
1361
1963
  * Scrolls down the page by a custom number of pixels specified by the user.
@@ -1457,29 +2059,32 @@ When(/^(I scroll|we scroll|scrolling)? to top of "([^"]*)"$/, function(pronounCa
1457
2059
  if (!selector || selector.trim() === '') {
1458
2060
  throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
1459
2061
  }
1460
-
2062
+
1461
2063
  // Validate selector format (basic check)
1462
2064
  if (selector.includes('"') || selector.includes("'")) {
1463
2065
  throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
1464
2066
  }
1465
-
2067
+
1466
2068
  try {
2069
+ // Wait for element to be present (allows dynamic elements to load)
2070
+ browser.waitForElementPresent(selector, 5000);
2071
+
1467
2072
  // Check if element exists before scrolling
1468
2073
  const elementExists = browser.executeScript(`
1469
2074
  return document.querySelector("${selector}") !== null;
1470
2075
  `);
1471
-
2076
+
1472
2077
  if (!elementExists) {
1473
2078
  throw new Error(`Element with selector "${selector}" not found.`);
1474
2079
  }
1475
-
2080
+
1476
2081
  browser.executeScript(`
1477
2082
  const element = document.querySelector("${selector}");
1478
2083
  if (element) {
1479
2084
  element.scrollTop = 0;
1480
2085
  }
1481
2086
  `);
1482
-
2087
+
1483
2088
  return browser.pause(2000);
1484
2089
  } catch (error) {
1485
2090
  throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
@@ -1498,29 +2103,32 @@ When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, function(pronou
1498
2103
  if (!selector || selector.trim() === '') {
1499
2104
  throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
1500
2105
  }
1501
-
2106
+
1502
2107
  // Validate selector format (basic check)
1503
2108
  if (selector.includes('"') || selector.includes("'")) {
1504
2109
  throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
1505
2110
  }
1506
-
2111
+
1507
2112
  try {
2113
+ // Wait for element to be present (allows dynamic elements to load)
2114
+ browser.waitForElementPresent(selector, 5000);
2115
+
1508
2116
  // Check if element exists before scrolling
1509
2117
  const elementExists = browser.executeScript(`
1510
2118
  return document.querySelector("${selector}") !== null;
1511
2119
  `);
1512
-
2120
+
1513
2121
  if (!elementExists) {
1514
2122
  throw new Error(`Element with selector "${selector}" not found.`);
1515
2123
  }
1516
-
2124
+
1517
2125
  browser.executeScript(`
1518
2126
  const element = document.querySelector("${selector}");
1519
2127
  if (element) {
1520
2128
  element.scrollTop = element.scrollHeight;
1521
2129
  }
1522
2130
  `);
1523
-
2131
+
1524
2132
  return browser.pause(2000);
1525
2133
  } catch (error) {
1526
2134
  throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
@@ -1627,29 +2235,32 @@ When(/^(I scroll|we scroll|scrolling)? to start of "([^"]*)"$/, function(pronoun
1627
2235
  if (!selector || selector.trim() === '') {
1628
2236
  throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
1629
2237
  }
1630
-
2238
+
1631
2239
  // Validate selector format (basic check)
1632
2240
  if (selector.includes('"') || selector.includes("'")) {
1633
2241
  throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
1634
2242
  }
1635
-
2243
+
1636
2244
  try {
2245
+ // Wait for element to be present (allows dynamic elements to load)
2246
+ browser.waitForElementPresent(selector, 5000);
2247
+
1637
2248
  // Check if element exists before scrolling
1638
2249
  const elementExists = browser.executeScript(`
1639
2250
  return document.querySelector("${selector}") !== null;
1640
2251
  `);
1641
-
2252
+
1642
2253
  if (!elementExists) {
1643
2254
  throw new Error(`Element with selector "${selector}" not found.`);
1644
2255
  }
1645
-
2256
+
1646
2257
  browser.executeScript(`
1647
2258
  const element = document.querySelector("${selector}");
1648
2259
  if (element) {
1649
2260
  element.scrollTop = 0;
1650
2261
  }
1651
2262
  `);
1652
-
2263
+
1653
2264
  return browser.pause(2000);
1654
2265
  } catch (error) {
1655
2266
  throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
@@ -1668,31 +2279,395 @@ When(/^(I scroll|we scroll|scrolling)? to end of "([^"]*)"$/, function(pronounCa
1668
2279
  if (!selector || selector.trim() === '') {
1669
2280
  throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
1670
2281
  }
1671
-
2282
+
1672
2283
  // Validate selector format (basic check)
1673
2284
  if (selector.includes('"') || selector.includes("'")) {
1674
2285
  throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
1675
2286
  }
1676
-
2287
+
1677
2288
  try {
2289
+ // Wait for element to be present (allows dynamic elements to load)
2290
+ browser.waitForElementPresent(selector, 5000);
2291
+
1678
2292
  // Check if element exists before scrolling
1679
2293
  const elementExists = browser.executeScript(`
1680
2294
  return document.querySelector("${selector}") !== null;
1681
2295
  `);
1682
-
2296
+
1683
2297
  if (!elementExists) {
1684
2298
  throw new Error(`Element with selector "${selector}" not found.`);
1685
2299
  }
1686
-
2300
+
1687
2301
  browser.executeScript(`
1688
2302
  const element = document.querySelector("${selector}");
1689
2303
  if (element) {
1690
2304
  element.scrollTop = element.scrollWidth;
1691
2305
  }
1692
2306
  `);
1693
-
2307
+
1694
2308
  return browser.pause(2000);
1695
2309
  } catch (error) {
1696
2310
  throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
1697
2311
  }
1698
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
+ });