@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.
- package/dist/strategies/index.d.ts +9 -0
- package/dist/strategies/index.js +49 -54
- package/package.json +1 -1
|
@@ -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
|
};
|
package/dist/strategies/index.js
CHANGED
|
@@ -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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
85
|
+
// Optional: Keyboard press for robust grid handling
|
|
90
86
|
try {
|
|
91
|
-
yield
|
|
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