@rickcedwhat/playwright-smart-table 6.24.0-next.82106e1 → 6.24.0-next.b538792
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/engine/rowFinder.d.ts +2 -0
- package/dist/engine/rowFinder.js +13 -4
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/smartRow.js +4 -2
- package/dist/useTable.js +10 -2
- package/dist/utils/locatorDescription.d.ts +15 -0
- package/dist/utils/locatorDescription.js +56 -0
- package/package.json +1 -1
|
@@ -25,6 +25,8 @@ export declare class RowFinder<T = any> {
|
|
|
25
25
|
maxPages?: number;
|
|
26
26
|
}): Promise<SmartRow<T>>;
|
|
27
27
|
private waitForTableReady;
|
|
28
|
+
/** Unfiltered rows keep the plain `SmartRow #n` name that `_makeSmart` applies. */
|
|
29
|
+
private nameFilteredRow;
|
|
28
30
|
findRows(filters?: Record<string, FilterValue>, options?: {
|
|
29
31
|
exact?: boolean;
|
|
30
32
|
maxPages?: number;
|
package/dist/engine/rowFinder.js
CHANGED
|
@@ -9,6 +9,7 @@ const navigationBarrier_1 = require("../utils/navigationBarrier");
|
|
|
9
9
|
const rowResolution_1 = require("./rowResolution");
|
|
10
10
|
const resolveCellLocator_1 = require("../utils/resolveCellLocator");
|
|
11
11
|
const scanPages_1 = require("./scanPages");
|
|
12
|
+
const locatorDescription_1 = require("../utils/locatorDescription");
|
|
12
13
|
const loadingWait_1 = require("../utils/loadingWait");
|
|
13
14
|
class RowFinder {
|
|
14
15
|
constructor(rootLocator, config, resolve, filterEngine, tableMapper, makeSmartRow, tableState = { currentPageIndex: 0 }, advancePage = async () => false) {
|
|
@@ -111,12 +112,13 @@ class RowFinder {
|
|
|
111
112
|
await (0, debugUtils_1.debugDelay)(this.config, 'findRow');
|
|
112
113
|
const map = await this.tableMapper.getMap();
|
|
113
114
|
const resolved = await this.resolveRowIndex(rowLocator);
|
|
114
|
-
|
|
115
|
+
const describedRow = (0, locatorDescription_1.describeLocator)(rowLocator, (0, locatorDescription_1.describeRowByFilters)(filters), this.config);
|
|
116
|
+
return this.makeSmartRow(describedRow, map, resolved === null || resolved === void 0 ? void 0 : resolved.index, this.tableState.currentPageIndex, undefined, resolved === null || resolved === void 0 ? void 0 : resolved.selector);
|
|
115
117
|
}
|
|
116
118
|
(0, debugUtils_1.logDebug)(this.config, 'error', 'Row not found', filters);
|
|
117
119
|
await (0, debugUtils_1.debugDelay)(this.config, 'findRow');
|
|
118
|
-
const sentinel = this.resolve(this.config.rowSelector, this.rootLocator)
|
|
119
|
-
.filter({ hasText: "___SENTINEL_ROW_NOT_FOUND___" + Date.now() });
|
|
120
|
+
const sentinel = (0, locatorDescription_1.describeLocator)(this.resolve(this.config.rowSelector, this.rootLocator)
|
|
121
|
+
.filter({ hasText: "___SENTINEL_ROW_NOT_FOUND___" + Date.now() }), (0, locatorDescription_1.describeSentinelRow)(filters), this.config);
|
|
120
122
|
const smartRow = this.makeSmartRow(sentinel, await this.tableMapper.getMap(), undefined);
|
|
121
123
|
smartRow[sentinel_1.SENTINEL_ROW] = true;
|
|
122
124
|
return smartRow;
|
|
@@ -134,6 +136,12 @@ class RowFinder {
|
|
|
134
136
|
};
|
|
135
137
|
await (0, loadingWait_1.waitWhileTableLoading)(this.config, context, this.rootLocator.page(), 'waitForTableReady');
|
|
136
138
|
}
|
|
139
|
+
/** Unfiltered rows keep the plain `SmartRow #n` name that `_makeSmart` applies. */
|
|
140
|
+
nameFilteredRow(row, resolved, filters) {
|
|
141
|
+
if (!resolved || Object.keys(filters).length === 0)
|
|
142
|
+
return row;
|
|
143
|
+
return (0, locatorDescription_1.describeLocator)(row, (0, locatorDescription_1.describeRowByIndex)(resolved.index, filters), this.config);
|
|
144
|
+
}
|
|
137
145
|
async findRows(filters = {}, options) {
|
|
138
146
|
var _a;
|
|
139
147
|
var _b, _c;
|
|
@@ -168,7 +176,8 @@ class RowFinder {
|
|
|
168
176
|
const barrier = useBarrier ? new navigationBarrier_1.NavigationBarrier(newIndices.length) : undefined;
|
|
169
177
|
for (const idx of newIndices) {
|
|
170
178
|
const resolved = await (0, rowResolution_1.resolveLogicalRowIndex)(currentRows[idx], this.config, () => allRows.length);
|
|
171
|
-
const
|
|
179
|
+
const rowLocator = this.nameFilteredRow(currentRows[idx], resolved, filtersRecord);
|
|
180
|
+
const smartRow = this.makeSmartRow(rowLocator, map, resolved === null || resolved === void 0 ? void 0 : resolved.index, this.tableState.currentPageIndex, barrier, resolved === null || resolved === void 0 ? void 0 : resolved.selector);
|
|
172
181
|
const loadingOutcome = await (0, rowResolution_1.resolveRowLoading)(smartRow, this.config.strategies.loading, 'skip', (msg) => (0, debugUtils_1.logDebug)(this.config, 'verbose', `findRows: ${msg}`));
|
|
173
182
|
if (loadingOutcome !== 'process') {
|
|
174
183
|
barrier === null || barrier === void 0 ? void 0 : barrier.markFinished();
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Generated by scripts/embed-version.mjs from package.json
|
|
4
4
|
*/
|
|
5
5
|
/** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
|
|
6
|
-
export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.24.0-next.
|
|
6
|
+
export declare const PLAYWRIGHT_SMART_TABLE_VERSION: "6.24.0-next.b538792";
|
package/dist/packageVersion.js
CHANGED
|
@@ -6,4 +6,4 @@ exports.PLAYWRIGHT_SMART_TABLE_VERSION = void 0;
|
|
|
6
6
|
* Generated by scripts/embed-version.mjs from package.json
|
|
7
7
|
*/
|
|
8
8
|
/** Semver of this package. Use in logs or diagnostics to confirm the installed build. */
|
|
9
|
-
exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.24.0-next.
|
|
9
|
+
exports.PLAYWRIGHT_SMART_TABLE_VERSION = "6.24.0-next.b538792";
|
package/dist/smartRow.js
CHANGED
|
@@ -7,6 +7,7 @@ const debugUtils_1 = require("./utils/debugUtils");
|
|
|
7
7
|
const paginationPath_1 = require("./utils/paginationPath");
|
|
8
8
|
const sentinel_1 = require("./utils/sentinel");
|
|
9
9
|
const pageIndex_1 = require("./utils/pageIndex");
|
|
10
|
+
const locatorDescription_1 = require("./utils/locatorDescription");
|
|
10
11
|
/**
|
|
11
12
|
* Internal helper to navigate to a cell with active cell optimization.
|
|
12
13
|
* Uses `strategies.navigation` primitives (goUp/goDown/goLeft/goRight, optional snap/seek/goHome).
|
|
@@ -328,7 +329,7 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
328
329
|
// Attach Methods
|
|
329
330
|
smart.getCell = (colName) => {
|
|
330
331
|
var _a;
|
|
331
|
-
var _b;
|
|
332
|
+
var _b, _c;
|
|
332
333
|
if ((_a = config.syntheticColumns) === null || _a === void 0 ? void 0 : _a[colName]) {
|
|
333
334
|
throw new Error(`Column "${colName}" is synthetic (no DOM cell) — use getValue("${colName}") or toJSON() instead`);
|
|
334
335
|
}
|
|
@@ -351,7 +352,8 @@ const createSmartRow = (rowLocator, map, rowIndex, config, rootLocator, resolve,
|
|
|
351
352
|
else {
|
|
352
353
|
baseLocator = resolve(config.cellSelector, rowLocator).nth(idx);
|
|
353
354
|
}
|
|
354
|
-
const
|
|
355
|
+
const cellDescription = `${(_c = (0, locatorDescription_1.getLocatorDescription)(rowLocator)) !== null && _c !== void 0 ? _c : 'SmartRow'} › "${colName}" cell`;
|
|
356
|
+
const smartCell = (0, locatorDescription_1.describeLocator)(baseLocator, cellDescription, config);
|
|
355
357
|
smartCell.bringIntoView = async () => {
|
|
356
358
|
const page = rootLocator.page();
|
|
357
359
|
const navigatedCell = await _navigateToCell({
|
package/dist/useTable.js
CHANGED
|
@@ -35,6 +35,7 @@ const elementTracker_1 = require("./utils/elementTracker");
|
|
|
35
35
|
const loadingWait_1 = require("./utils/loadingWait");
|
|
36
36
|
const pageIndex_1 = require("./utils/pageIndex");
|
|
37
37
|
const smartRowInternals_1 = require("./utils/smartRowInternals");
|
|
38
|
+
const locatorDescription_1 = require("./utils/locatorDescription");
|
|
38
39
|
// Helper to safely serialize objects containing functions for logging
|
|
39
40
|
const safeStringify = (obj) => {
|
|
40
41
|
try {
|
|
@@ -153,7 +154,13 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
153
154
|
const effectiveLocator = healSelector
|
|
154
155
|
? rootLocator.locator(healSelector)
|
|
155
156
|
: rowLocator;
|
|
156
|
-
|
|
157
|
+
// Keep a caller-supplied description (e.g. the filters) across self-healing; otherwise name the row by index.
|
|
158
|
+
const existingDescription = (0, locatorDescription_1.getLocatorDescription)(rowLocator);
|
|
159
|
+
const description = existingDescription !== null && existingDescription !== void 0 ? existingDescription : (rowIndex !== undefined ? (0, locatorDescription_1.describeRowByIndex)(rowIndex) : undefined);
|
|
160
|
+
const describedLocator = description !== undefined && (healSelector !== undefined || existingDescription === undefined)
|
|
161
|
+
? (0, locatorDescription_1.describeLocator)(effectiveLocator, description, config)
|
|
162
|
+
: effectiveLocator;
|
|
163
|
+
const sr = (0, smartRow_1.default)(describedLocator, map, rowIndex, config, rootLocator, resolve, finalTable, tablePageIndex, barrier, renderWindowPosition);
|
|
157
164
|
if (healSelector)
|
|
158
165
|
(0, smartRowInternals_1.internals)(sr)._selfHealing = true;
|
|
159
166
|
return sr;
|
|
@@ -514,7 +521,8 @@ const useTable = (rootLocator, configOptions = {}) => {
|
|
|
514
521
|
throw new Error('Initialization Error: You attempted to access a row before the table structure was mapped. Please call "await table.init()" once before using synchronous row access.');
|
|
515
522
|
const allRows = resolve(config.rowSelector, rootLocator);
|
|
516
523
|
const matchedRows = filterEngine.applyFilters(allRows, filters, map, options.exact || false, rootLocator.page(), rootLocator);
|
|
517
|
-
|
|
524
|
+
const describedRows = (0, locatorDescription_1.describeLocator)(matchedRows, (0, locatorDescription_1.describeRowByFilters)(filters), config);
|
|
525
|
+
return _makeSmart(describedRows, map, undefined); // sync path cannot compute real index
|
|
518
526
|
},
|
|
519
527
|
getRowByIndex: (index) => {
|
|
520
528
|
log(`getRowByIndex: index=${index}`);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Locator } from '@playwright/test';
|
|
2
|
+
import type { FilterValue, FinalTableConfig } from '../types';
|
|
3
|
+
/** `Name="Alice", Status=/act/i` — readable in traces, unlike JSON.stringify (which turns RegExp into `{}`). */
|
|
4
|
+
export declare const formatFilters: (filters: Record<string, FilterValue>) => string;
|
|
5
|
+
export declare const describeRowByFilters: (filters: Record<string, FilterValue>) => string;
|
|
6
|
+
/** `SmartRow #3`, or `SmartRow #3 where Dept="Eng"` when the row came from a filtered search. */
|
|
7
|
+
export declare const describeRowByIndex: (rowIndex: number, filters?: Record<string, FilterValue>) => string;
|
|
8
|
+
export declare const describeSentinelRow: (filters: Record<string, FilterValue>) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Applies `locator.describe()` (Playwright 1.53+) so traces, HTML reports and error messages show a
|
|
11
|
+
* readable name instead of the raw selector chain. Older Playwright versions get the locator back unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare const describeLocator: (locator: Locator, description: string, config?: FinalTableConfig) => Locator;
|
|
14
|
+
/** The description already applied to a locator, or undefined (unsupported or never described). */
|
|
15
|
+
export declare const getLocatorDescription: (locator: Locator) => string | undefined;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocatorDescription = exports.describeLocator = exports.describeSentinelRow = exports.describeRowByIndex = exports.describeRowByFilters = exports.formatFilters = void 0;
|
|
4
|
+
const debugUtils_1 = require("./debugUtils");
|
|
5
|
+
const MAX_VALUE_LENGTH = 40;
|
|
6
|
+
const locatorDescriptions = new WeakMap();
|
|
7
|
+
let loggedUnsupported = false;
|
|
8
|
+
const formatFilterValue = (value) => {
|
|
9
|
+
if (value instanceof RegExp)
|
|
10
|
+
return value.toString();
|
|
11
|
+
if (typeof value === 'function')
|
|
12
|
+
return '<locator filter>';
|
|
13
|
+
if (typeof value === 'number')
|
|
14
|
+
return String(value);
|
|
15
|
+
const text = value.length > MAX_VALUE_LENGTH ? `${value.slice(0, MAX_VALUE_LENGTH)}…` : value;
|
|
16
|
+
return JSON.stringify(text);
|
|
17
|
+
};
|
|
18
|
+
/** `Name="Alice", Status=/act/i` — readable in traces, unlike JSON.stringify (which turns RegExp into `{}`). */
|
|
19
|
+
const formatFilters = (filters) => Object.entries(filters).map(([col, value]) => `${col}=${formatFilterValue(value)}`).join(', ');
|
|
20
|
+
exports.formatFilters = formatFilters;
|
|
21
|
+
const describeRowByFilters = (filters) => {
|
|
22
|
+
const formatted = (0, exports.formatFilters)(filters);
|
|
23
|
+
return formatted ? `SmartRow where ${formatted}` : 'SmartRow';
|
|
24
|
+
};
|
|
25
|
+
exports.describeRowByFilters = describeRowByFilters;
|
|
26
|
+
/** `SmartRow #3`, or `SmartRow #3 where Dept="Eng"` when the row came from a filtered search. */
|
|
27
|
+
const describeRowByIndex = (rowIndex, filters = {}) => {
|
|
28
|
+
const formatted = (0, exports.formatFilters)(filters);
|
|
29
|
+
return formatted ? `SmartRow #${rowIndex} where ${formatted}` : `SmartRow #${rowIndex}`;
|
|
30
|
+
};
|
|
31
|
+
exports.describeRowByIndex = describeRowByIndex;
|
|
32
|
+
const describeSentinelRow = (filters) => {
|
|
33
|
+
const formatted = (0, exports.formatFilters)(filters);
|
|
34
|
+
return formatted ? `SmartRow not found: ${formatted}` : 'SmartRow not found';
|
|
35
|
+
};
|
|
36
|
+
exports.describeSentinelRow = describeSentinelRow;
|
|
37
|
+
/**
|
|
38
|
+
* Applies `locator.describe()` (Playwright 1.53+) so traces, HTML reports and error messages show a
|
|
39
|
+
* readable name instead of the raw selector chain. Older Playwright versions get the locator back unchanged.
|
|
40
|
+
*/
|
|
41
|
+
const describeLocator = (locator, description, config) => {
|
|
42
|
+
if (typeof locator.describe === 'function') {
|
|
43
|
+
const described = locator.describe(description);
|
|
44
|
+
locatorDescriptions.set(described, description);
|
|
45
|
+
return described;
|
|
46
|
+
}
|
|
47
|
+
if ((config === null || config === void 0 ? void 0 : config.debug) && !loggedUnsupported) {
|
|
48
|
+
loggedUnsupported = true;
|
|
49
|
+
(0, debugUtils_1.logDebug)(config, 'info', 'Upgrade @playwright/test to 1.53+ to see SmartRow / SmartCell names in traces and error messages');
|
|
50
|
+
}
|
|
51
|
+
return locator;
|
|
52
|
+
};
|
|
53
|
+
exports.describeLocator = describeLocator;
|
|
54
|
+
/** The description already applied to a locator, or undefined (unsupported or never described). */
|
|
55
|
+
const getLocatorDescription = (locator) => { var _a; return typeof locator.description === 'function' ? (_a = locator.description()) !== null && _a !== void 0 ? _a : undefined : locatorDescriptions.get(locator); };
|
|
56
|
+
exports.getLocatorDescription = getLocatorDescription;
|
package/package.json
CHANGED