webship-js 1.0.43 → 1.0.45

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 (71) hide show
  1. package/.eslintrc.json +0 -0
  2. package/CNAME +0 -0
  3. package/dist/nightwatch.conf.dev.js +93 -0
  4. package/examples/about-us.html +0 -0
  5. package/examples/contact-us.html +0 -0
  6. package/examples/index.html +0 -0
  7. package/examples/test--then--i-should--see-text-in-element.html +0 -0
  8. package/examples/test--then--i-should--see-text-matching-pattern.html +0 -0
  9. package/examples/test--then--the-checkbox-checked.html +0 -0
  10. package/examples/test--then--the-element-should_not-contain-cssproperty.html +0 -0
  11. package/examples/test--then--the-link-should-contain.html +0 -0
  12. package/examples/test--when--i-attach-file-to-feild.html +0 -0
  13. package/examples/test--when--i-check-uncheck-checkbox.html +0 -0
  14. package/examples/test--when--i-click-link.html +0 -0
  15. package/examples/test--when--i-press-button.html +0 -0
  16. package/examples/test--when--i-reload-page.html +0 -0
  17. package/examples/test--when--i-scroll-functionality.html +0 -0
  18. package/examples/test--when--i-scroll-left-right-functionality.html +0 -0
  19. package/examples/test--when--i-select-option-from-dropdownlist.html +0 -0
  20. package/examples/test--when-i-wait-max-of-time.html +0 -0
  21. package/examples/test--when-i-wait-page-until-is-loaded.html +0 -0
  22. package/examples/test--when-i-wait-specific-time.html +0 -0
  23. package/generate-reports.js +0 -0
  24. package/nightwatch.conf.js +1 -1
  25. package/package.json +1 -1
  26. package/tests/assets/webshipco.png +0 -0
  27. package/tests/features/api-step-definitions-individual.feature +185 -0
  28. package/tests/features/complete-api-testing-examples.feature +205 -0
  29. package/tests/features/test--given--i-am-on-homepage.feature +2 -2
  30. package/tests/features/test--then--i-should--not--see-text-in-element.feature +2 -2
  31. package/tests/features/test--then--i-should--see-text-in-element-by-attr.feature +2 -2
  32. package/tests/features/test--then--i-should--see-text-in-element.feature +2 -2
  33. package/tests/features/test--then--i-should--see-text-matching-pattern-in-element.feature +2 -2
  34. package/tests/features/test--then--i-should--see-text-matching-pattern.feature +2 -2
  35. package/tests/features/test--then--i-should-be-on-page.feature +2 -2
  36. package/tests/features/test--then--i-should-be-on-the-homepage.feature +2 -2
  37. package/tests/features/test--then--i-should-not-see-an-element-by-attr.feature +2 -2
  38. package/tests/features/test--then--i-should-not-see-an-element.feature +2 -2
  39. package/tests/features/test--then--i-should-see-an-element-by-attr.feature +2 -2
  40. package/tests/features/test--then--i-should-see-an-element.feature +2 -2
  41. package/tests/features/test--then--i-should-see-text-in-table-row.feature +2 -2
  42. package/tests/features/test--then--the-checkbox-is-checked.feature +2 -2
  43. package/tests/features/test--then--the-checkbox-should-be-checked.feature +2 -2
  44. package/tests/features/test--then--the-element-should-contain-cssproperty.feature +2 -2
  45. package/tests/features/test--then--the-element-should-not-contain-cssproperty.feature +2 -2
  46. package/tests/features/test--then--the-field-should-contain-value.feature +2 -2
  47. package/tests/features/test--then--the-response-should-contain.feature +2 -2
  48. package/tests/features/test--then--the-response-status-code-should-be.feature +2 -2
  49. package/tests/features/test--then--the-url-should-match.feature +2 -2
  50. package/tests/features/test--then-the-link-should-contain-by-attribute.feature +2 -2
  51. package/tests/features/test--then-the-link-should-contain.feature +2 -2
  52. package/tests/features/test--when--i-attach-file-to-feild.feature +2 -2
  53. package/tests/features/test--when--i-check-checkbox.feature +2 -2
  54. package/tests/features/test--when--i-click-link-by-attribute.feature +2 -2
  55. package/tests/features/test--when--i-click-link.feature +2 -2
  56. package/tests/features/test--when--i-click-text-in-table-row.feature +21 -21
  57. package/tests/features/test--when--i-fill-in-by-attr.feature +2 -2
  58. package/tests/features/test--when--i-fill-in-table-by-attr.feature +2 -2
  59. package/tests/features/test--when--i-fill-in.feature +2 -2
  60. package/tests/features/test--when--i-go-to-homepage.feature +3 -3
  61. package/tests/features/test--when--i-move-forward-backward-one-page.feature +2 -2
  62. package/tests/features/test--when--i-press-button-by-attribute.feature +2 -2
  63. package/tests/features/test--when--i-press-button.feature +2 -2
  64. package/tests/features/test--when--i-reload-page.feature +2 -2
  65. package/tests/features/test--when--i-scroll-left-right.feature +2 -2
  66. package/tests/features/test--when--i-scroll.feature +2 -2
  67. package/tests/features/test--when--i-select-option-from-dropdownlist.feature +2 -2
  68. package/tests/features/test--when--i-wait-page-is-loaded.feature +2 -2
  69. package/tests/features/test--when--i-wait-time.feature +2 -2
  70. package/tests/step-definitions/webship-api.js +547 -0
  71. package/tests/step-definitions/webship.js +71 -62
@@ -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
  }
@@ -265,71 +265,80 @@ When(/^(I |we )*click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, fun
265
265
  */
266
266
  When(/^(I |we )*click "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, clickText, theCase, rowIdentifier) {
267
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) {
268
+ return browser.execute(function(rowId, targetText) {
269
+ // Find all tables on the page
270
+ const tables = document.querySelectorAll('table');
271
+ if (tables.length === 0) {
271
272
  throw new Error('No tables found on the page');
272
273
  }
273
274
 
274
275
  // 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;
301
- return;
302
- }
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
- });
320
- });
276
+ for (let table of tables) {
277
+ const rows = table.querySelectorAll('tr');
278
+ for (let row of rows) {
279
+ const rowText = row.textContent || row.innerText;
280
+ if (rowText.includes(rowId)) {
281
+ // Found the correct row, now look for clickable elements with the target text
282
+
283
+ // First, try to find exact text matches in clickable elements
284
+ const clickableElements = row.querySelectorAll('a, button, [onclick], [role="button"], .btn, input[type="submit"], input[type="button"]');
285
+ for (let element of clickableElements) {
286
+ const elementText = (element.textContent || element.innerText || element.value || '').trim();
287
+ if (elementText === targetText) {
288
+ element.click();
289
+ return { success: true, element: element.tagName };
321
290
  }
322
- });
323
- });
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.`);
291
+ }
292
+
293
+ // If not found in obvious clickable elements, search all elements
294
+ const allElements = row.querySelectorAll('*');
295
+ for (let element of allElements) {
296
+ const elementText = (element.textContent || element.innerText || '').trim();
297
+ if (elementText === targetText) {
298
+ // Check if element or parent is clickable
299
+ let clickableParent = element;
300
+ while (clickableParent && clickableParent !== row) {
301
+ if (clickableParent.tagName === 'A' ||
302
+ clickableParent.tagName === 'BUTTON' ||
303
+ clickableParent.onclick ||
304
+ clickableParent.getAttribute('role') === 'button' ||
305
+ clickableParent.classList.contains('btn') ||
306
+ clickableParent.style.cursor === 'pointer') {
307
+ clickableParent.click();
308
+ return { success: true, element: clickableParent.tagName };
309
+ }
310
+ clickableParent = clickableParent.parentElement;
311
+ }
312
+
313
+ // If no clickable parent found, try clicking the element itself
314
+ try {
315
+ element.click();
316
+ return { success: true, element: element.tagName };
317
+ } catch (e) {
318
+ // Continue searching if click failed
319
+ continue;
320
+ }
321
+ }
322
+ }
323
+
324
+ // Row found but target text not clickable
325
+ return {
326
+ success: false,
327
+ error: `Found row containing "${rowId}" but could not find clickable "${targetText}" within it. Row contains: ${rowText.substring(0, 200)}...`
328
+ };
329
+ }
330
+ }
331
+ }
332
+
333
+ // Row not found
334
+ return {
335
+ success: false,
336
+ error: `Could not find row containing "${rowId}". Available rows: ${Array.from(document.querySelectorAll('table tr')).map(r => (r.textContent || '').substring(0, 50)).join(', ')}`
337
+ };
338
+
339
+ }, [rowIdentifier, clickText], function(result) {
340
+ if (!result.value.success) {
341
+ throw new Error(result.value.error || `Could not find "${clickText}" in the "${rowIdentifier}" row. Please verify the table structure and text content.`);
333
342
  }
334
343
  });
335
344
  });