flexysnap 0.2.5 → 0.2.7
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/README.md +15 -8
- package/package.json +1 -1
- package/src/testUtils.js +5 -0
- package/src/wireframeUtils.js +2 -1
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ const elementGroups = [
|
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
- `strictPosition: false` — compare element size only, not exact position.
|
|
47
|
+
- `strictSize: false` — for position-tolerant groups, compare size by ratio rather than absolute pixel difference.
|
|
47
48
|
- `maskDigits: true` — replace digit runs with a placeholder before comparing text.
|
|
48
49
|
- `textIgnoreClasses` — skip text found inside elements carrying these class names, at any ancestor level.
|
|
49
50
|
|
|
@@ -95,6 +96,7 @@ test('product page wireframe', async ({ page }) => {
|
|
|
95
96
|
"timestamp": "2024-01-01T00:00:00.000Z",
|
|
96
97
|
"scrollPosition": { "x": 0, "y": 0 },
|
|
97
98
|
"screenshotScrollPosition": { "x": 0, "y": 0 },
|
|
99
|
+
"deviceScaleFactor": 1,
|
|
98
100
|
"elementGroups": [
|
|
99
101
|
{
|
|
100
102
|
"selector": ".product-title",
|
|
@@ -127,11 +129,14 @@ Anything passed as `options.metadata` is merged into the top level of this objec
|
|
|
127
129
|
### Test utilities
|
|
128
130
|
|
|
129
131
|
- `waitForCompleteLoad(page)` — wait for `domcontentloaded`, `load`, and a settle delay.
|
|
132
|
+
- `gotoWithRetry(page, url)` — navigate to a URL, retrying once on failure, then wait for the page to finish loading.
|
|
130
133
|
- `click(page, locator)` — resilient click that closes popups, re-hovers, scrolls into view, and retries.
|
|
131
134
|
- `highlightedClick(page, locator)` — scroll a locator into the viewport and force-click it.
|
|
132
135
|
- `hover(page, locator)` — hover a locator and remember it for re-hovering.
|
|
133
136
|
- `rehover(page)` — re-hover the last hovered locator.
|
|
134
137
|
- `fill(page, field, value)` — click and fill an input by name or locator.
|
|
138
|
+
- `selectOption(page, field, value)` — click and select an option by name or locator.
|
|
139
|
+
- `scrollToTopOfElement(page, target, offset?)` — scroll so a locator (or selector string) is positioned near the top of the viewport, minus an optional offset in pixels.
|
|
135
140
|
- `setClosePopups(fn)` — register a function used to dismiss popups before interactions.
|
|
136
141
|
- `setBaseUrl(url)` — set the base URL used for request cache-busting.
|
|
137
142
|
- `logTimestamp(eventName)` — log an event with elapsed time since test start.
|
|
@@ -142,20 +147,22 @@ Anything passed as `options.metadata` is merged into the top level of this objec
|
|
|
142
147
|
- `options.retryDelay` (default `1000`) — minimum milliseconds between stability samples.
|
|
143
148
|
- `options.maxRetryCount` (default `10`) — maximum number of extraction attempts.
|
|
144
149
|
- `options.metadata` (default `{}`) — extra fields merged into the written JSON.
|
|
150
|
+
- `options.closePopups` (default no-op) — function called before each element group extraction to dismiss popups.
|
|
145
151
|
- `getRGBHistogramFromBuffer(buffer)` — compute a 48-bin RGB histogram (16 bins per channel, values normalized to percentages) from an image buffer.
|
|
146
152
|
|
|
147
153
|
### Wireframe comparison
|
|
148
154
|
|
|
149
|
-
- `compareWireframes(baselineWireframe, currentWireframe)` — diff two wireframes and
|
|
150
|
-
- `compareElements(baselineElement, currentElement, strictPosition?, maskDigits?)`
|
|
151
|
-
- `compareTexts(baselineTexts, currentTexts, strictPosition?, maskDigits?)`
|
|
152
|
-
- `compareBoundingBoxes(baselineRect, currentRect, tolerance?, strictPosition?)`
|
|
153
|
-
- `createPairings(currentElements, baselineElements)` — nearest bounding-box matching between two element sets, returning `{ matchedPairs, unmatchedCurrent, unmatchedBaseline }`.
|
|
154
|
-
- `histogramDiff(a, b)` — sum of absolute differences between two histograms.
|
|
155
|
+
- `compareWireframes(baselineWireframe, currentWireframe)` — diff two wireframes and return the current wireframe annotated with `differences`. Element groups are matched by index and must appear in the same order and count in both wireframes. Within each group, elements are paired with the baseline using nearest bounding-box matching, then diffed for layout shifts, size mismatches, text mismatches, and image histogram differences. Elements missing from the current capture are appended to the current wireframe's element groups so they still appear in the output, marked as `missing_element` (or `missing_text`).
|
|
155
156
|
|
|
156
157
|
### Stability
|
|
157
158
|
|
|
158
|
-
- `areWireframesStable(previousWireframeData, currentWireframeData)` — determine whether two consecutive captures are stable enough to trust.
|
|
159
|
+
- `areWireframesStable(previousWireframeData, currentWireframeData)` — determine whether two consecutive captures are stable enough to trust, by checking for empty element groups, mismatched element counts, text content differences, and overall bounding-box size drift.
|
|
160
|
+
|
|
161
|
+
### Output paths
|
|
162
|
+
|
|
163
|
+
- `setWireframeOutputRoot(rootPath)` — set the root directory used to resolve relative output directories (defaults to `process.cwd()`).
|
|
164
|
+
- `getWireframeOutputRoot()` — get the currently configured output root.
|
|
165
|
+
- `resolveWireframeOutputDir(outputDir)` — resolve an output directory against the configured root; absolute paths are returned unchanged.
|
|
159
166
|
|
|
160
167
|
## How it works
|
|
161
168
|
|
|
@@ -243,4 +250,4 @@ Issues and pull requests are welcome. Please open an issue before submitting lar
|
|
|
243
250
|
|
|
244
251
|
## License
|
|
245
252
|
|
|
246
|
-
MIT
|
|
253
|
+
MIT
|
package/package.json
CHANGED
package/src/testUtils.js
CHANGED
|
@@ -2,6 +2,10 @@ import { test } from '@playwright/test';
|
|
|
2
2
|
|
|
3
3
|
let closePopups = async function(page) {}
|
|
4
4
|
|
|
5
|
+
async function callClosePopups(page) {
|
|
6
|
+
await closePopups(page);
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
async function gotoWithRetry(page, url) {
|
|
6
10
|
try {
|
|
7
11
|
logTimestamp('Loading ' + url);
|
|
@@ -209,6 +213,7 @@ export {
|
|
|
209
213
|
rehover,
|
|
210
214
|
scrollToTopOfElement,
|
|
211
215
|
setClosePopups,
|
|
216
|
+
callClosePopups,
|
|
212
217
|
logTimestamp,
|
|
213
218
|
setBaseUrl
|
|
214
219
|
};
|
package/src/wireframeUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { logTimestamp } from './testUtils.js';
|
|
3
|
+
import { logTimestamp, callClosePopups } from './testUtils.js';
|
|
4
4
|
import { loadImage, createCanvas } from 'canvas';
|
|
5
5
|
import { areWireframesStable } from './wireframeStability.js';
|
|
6
6
|
import { resolveWireframeOutputDir } from './wireframeOutput.js';
|
|
@@ -275,6 +275,7 @@ async function extractWireframe(page, elementGroups) {
|
|
|
275
275
|
const wireframeData = [];
|
|
276
276
|
|
|
277
277
|
for (let groupIndex = 0; groupIndex < elementGroups.length; groupIndex++) {
|
|
278
|
+
await callClosePopups(page);
|
|
278
279
|
const elementGroupData = await extractElementGroupData(page, elementGroups[groupIndex], groupIndex, FLEXYSNAP_ELEMENT_ID_ATTRIBUTE);
|
|
279
280
|
wireframeData.push(elementGroupData);
|
|
280
281
|
}
|