@rickcedwhat/playwright-smart-table 2.0.8 → 2.0.9

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.
@@ -1,6 +1,15 @@
1
1
  import { PaginationStrategy, Selector } from '../types';
2
2
  export declare const TableStrategies: {
3
+ /**
4
+ * Strategy: Clicks a "Next" button and waits for the first row of data to change.
5
+ */
3
6
  clickNext: (nextButtonSelector: Selector, timeout?: number) => PaginationStrategy;
7
+ /**
8
+ * Strategy: Clicks a "Load More" button and waits for the row count to increase.
9
+ */
4
10
  clickLoadMore: (buttonSelector: Selector, timeout?: number) => PaginationStrategy;
11
+ /**
12
+ * Strategy: Scrolls to the bottom and waits for more rows to appear.
13
+ */
5
14
  infiniteScroll: (timeout?: number) => PaginationStrategy;
6
15
  };
@@ -11,92 +11,87 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TableStrategies = void 0;
13
13
  /**
14
- * Helper to get 'expect' safely in ANY environment.
15
- * 1. Tries global scope (QA Wolf / Cloud Runners).
16
- * 2. Tries local require (Standard Playwright).
14
+ * Internal helper to wait for a condition to be met.
15
+ * Replaces the dependency on 'expect(...).toPass()' to ensure compatibility
16
+ * with environments like QA Wolf where 'expect' is not globally available.
17
17
  */
18
- const getExpect = () => {
19
- // 1. Priority: Global (Environment injected)
20
- const globalExpect = globalThis.expect;
21
- if (globalExpect)
22
- return globalExpect;
23
- // 2. Fallback: Module Import (Local development)
24
- // We use a try-catch with require to safely attempt loading the module
25
- // without crashing environments where the module doesn't exist.
26
- try {
27
- // eslint-disable-next-line @typescript-eslint/no-var-requires
28
- const { expect } = require('@playwright/test');
29
- if (expect)
30
- return expect;
18
+ const waitForCondition = (predicate, timeout, page // Context page for pauses
19
+ ) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const startTime = Date.now();
21
+ while (Date.now() - startTime < timeout) {
22
+ if (yield predicate()) {
23
+ return true;
24
+ }
25
+ // Wait 100ms before next check (Standard Polling)
26
+ yield page.waitForTimeout(100).catch(() => new Promise(r => setTimeout(r, 100)));
31
27
  }
32
- catch (e) {
33
- // Module not found or require not available.
34
- }
35
- // 3. Fatal Error
36
- throw new Error("@rickcedwhat/playwright-smart-table: 'expect' not found. Ensure you are running in a Playwright test.");
37
- };
28
+ return false;
29
+ });
38
30
  exports.TableStrategies = {
31
+ /**
32
+ * Strategy: Clicks a "Next" button and waits for the first row of data to change.
33
+ */
39
34
  clickNext: (nextButtonSelector, timeout = 5000) => {
40
- return (_a) => __awaiter(void 0, [_a], void 0, function* ({ root, config, resolve }) {
41
- // ✅ LAZY LOAD: Safe for both Local & Cloud
42
- const expect = getExpect();
35
+ return (_a) => __awaiter(void 0, [_a], void 0, function* ({ root, config, resolve, page }) {
43
36
  const nextBtn = resolve(nextButtonSelector, root).first();
37
+ // Check if button exists/enabled before clicking
44
38
  if (!(yield nextBtn.isVisible()) || !(yield nextBtn.isEnabled())) {
45
39
  return false;
46
40
  }
41
+ // 1. Snapshot current state
47
42
  const firstRow = resolve(config.rowSelector, root).first();
48
43
  const oldText = yield firstRow.innerText().catch(() => "");
44
+ // 2. Click
49
45
  yield nextBtn.click();
50
- try {
51
- yield expect(firstRow).not.toHaveText(oldText, { timeout });
52
- return true;
53
- }
54
- catch (e) {
55
- return false;
56
- }
46
+ // 3. Smart Wait (Polling) - No 'expect' needed
47
+ return yield waitForCondition(() => __awaiter(void 0, void 0, void 0, function* () {
48
+ const newText = yield firstRow.innerText().catch(() => "");
49
+ return newText !== oldText;
50
+ }), timeout, page);
57
51
  });
58
52
  },
53
+ /**
54
+ * Strategy: Clicks a "Load More" button and waits for the row count to increase.
55
+ */
59
56
  clickLoadMore: (buttonSelector, timeout = 5000) => {
60
- return (_a) => __awaiter(void 0, [_a], void 0, function* ({ root, config, resolve }) {
61
- const expect = getExpect(); // ✅ LAZY LOAD
57
+ return (_a) => __awaiter(void 0, [_a], void 0, function* ({ root, config, resolve, page }) {
62
58
  const loadMoreBtn = resolve(buttonSelector, root).first();
63
59
  if (!(yield loadMoreBtn.isVisible()) || !(yield loadMoreBtn.isEnabled())) {
64
60
  return false;
65
61
  }
62
+ // 1. Snapshot count
66
63
  const rows = resolve(config.rowSelector, root);
67
64
  const oldCount = yield rows.count();
65
+ // 2. Click
68
66
  yield loadMoreBtn.click();
69
- try {
70
- yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
71
- const newCount = yield rows.count();
72
- expect(newCount).toBeGreaterThan(oldCount);
73
- })).toPass({ timeout });
74
- return true;
75
- }
76
- catch (e) {
77
- return false;
78
- }
67
+ // 3. Smart Wait (Polling)
68
+ return yield waitForCondition(() => __awaiter(void 0, void 0, void 0, function* () {
69
+ const newCount = yield rows.count();
70
+ return newCount > oldCount;
71
+ }), timeout, page);
79
72
  });
80
73
  },
74
+ /**
75
+ * Strategy: Scrolls to the bottom and waits for more rows to appear.
76
+ */
81
77
  infiniteScroll: (timeout = 5000) => {
82
78
  return (_a) => __awaiter(void 0, [_a], void 0, function* ({ root, config, resolve, page }) {
83
- const expect = getExpect(); // ✅ LAZY LOAD
84
79
  const rows = resolve(config.rowSelector, root);
85
80
  const oldCount = yield rows.count();
86
81
  if (oldCount === 0)
87
82
  return false;
83
+ // 1. Trigger Scroll
88
84
  yield rows.last().scrollIntoViewIfNeeded();
89
- yield page.keyboard.press('End');
85
+ // Optional: Keyboard press for robust grid handling
90
86
  try {
91
- yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
92
- const newCount = yield rows.count();
93
- expect(newCount).toBeGreaterThan(oldCount);
94
- })).toPass({ timeout });
95
- return true;
96
- }
97
- catch (e) {
98
- return false;
87
+ yield page.keyboard.press('End');
99
88
  }
89
+ catch (e) { }
90
+ // 2. Smart Wait (Polling)
91
+ return yield waitForCondition(() => __awaiter(void 0, void 0, void 0, function* () {
92
+ const newCount = yield rows.count();
93
+ return newCount > oldCount;
94
+ }), timeout, page);
100
95
  });
101
96
  }
102
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-table",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "A smart table utility for Playwright with built-in pagination strategies that are fully extensible.",
5
5
  "repository": {
6
6
  "type": "git",