@testivai/witness-playwright 0.1.4 → 0.1.5
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/snapshot.js +30 -10
- package/package.json +1 -1
- package/src/snapshot.ts +32 -9
package/dist/snapshot.js
CHANGED
|
@@ -79,17 +79,37 @@ async function snapshot(page, testInfo, name, config) {
|
|
|
79
79
|
const baseFilename = `${timestamp}_${safeName}`;
|
|
80
80
|
// 1. Capture full-page screenshot
|
|
81
81
|
const screenshotPath = path.join(outputDir, `${baseFilename}.png`);
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
// Temporarily disable overflow constraints to enable full-page capture
|
|
83
|
+
await page.evaluate(`
|
|
84
|
+
window.__testivaiOriginalStyles = [];
|
|
85
|
+
document.querySelectorAll('*').forEach((el) => {
|
|
86
|
+
const computed = window.getComputedStyle(el);
|
|
87
|
+
if (computed.overflow === 'auto' || computed.overflow === 'scroll' ||
|
|
88
|
+
computed.overflowY === 'auto' || computed.overflowY === 'scroll') {
|
|
89
|
+
window.__testivaiOriginalStyles.push({
|
|
90
|
+
element: el,
|
|
91
|
+
overflow: el.style.overflow,
|
|
92
|
+
height: el.style.height
|
|
93
|
+
});
|
|
94
|
+
el.style.overflow = 'visible';
|
|
95
|
+
el.style.height = 'auto';
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
`);
|
|
99
|
+
// Wait for layout to stabilize
|
|
100
|
+
await page.waitForTimeout(200);
|
|
101
|
+
// Take full-page screenshot
|
|
92
102
|
await page.screenshot({ path: screenshotPath, fullPage: true });
|
|
103
|
+
// Restore original styles
|
|
104
|
+
await page.evaluate(`
|
|
105
|
+
if (window.__testivaiOriginalStyles) {
|
|
106
|
+
window.__testivaiOriginalStyles.forEach((item) => {
|
|
107
|
+
item.element.style.overflow = item.overflow;
|
|
108
|
+
item.element.style.height = item.height;
|
|
109
|
+
});
|
|
110
|
+
delete window.__testivaiOriginalStyles;
|
|
111
|
+
}
|
|
112
|
+
`);
|
|
93
113
|
// 2. Dump full-page DOM
|
|
94
114
|
const domPath = path.join(outputDir, `${baseFilename}.html`);
|
|
95
115
|
const htmlContent = await page.content();
|
package/package.json
CHANGED
package/src/snapshot.ts
CHANGED
|
@@ -56,17 +56,40 @@ export async function snapshot(
|
|
|
56
56
|
// 1. Capture full-page screenshot
|
|
57
57
|
const screenshotPath = path.join(outputDir, `${baseFilename}.png`);
|
|
58
58
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
// Temporarily disable overflow constraints to enable full-page capture
|
|
60
|
+
await page.evaluate(`
|
|
61
|
+
window.__testivaiOriginalStyles = [];
|
|
62
|
+
document.querySelectorAll('*').forEach((el) => {
|
|
63
|
+
const computed = window.getComputedStyle(el);
|
|
64
|
+
if (computed.overflow === 'auto' || computed.overflow === 'scroll' ||
|
|
65
|
+
computed.overflowY === 'auto' || computed.overflowY === 'scroll') {
|
|
66
|
+
window.__testivaiOriginalStyles.push({
|
|
67
|
+
element: el,
|
|
68
|
+
overflow: el.style.overflow,
|
|
69
|
+
height: el.style.height
|
|
70
|
+
});
|
|
71
|
+
el.style.overflow = 'visible';
|
|
72
|
+
el.style.height = 'auto';
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
`);
|
|
68
76
|
|
|
77
|
+
// Wait for layout to stabilize
|
|
78
|
+
await page.waitForTimeout(200);
|
|
79
|
+
|
|
80
|
+
// Take full-page screenshot
|
|
69
81
|
await page.screenshot({ path: screenshotPath, fullPage: true });
|
|
82
|
+
|
|
83
|
+
// Restore original styles
|
|
84
|
+
await page.evaluate(`
|
|
85
|
+
if (window.__testivaiOriginalStyles) {
|
|
86
|
+
window.__testivaiOriginalStyles.forEach((item) => {
|
|
87
|
+
item.element.style.overflow = item.overflow;
|
|
88
|
+
item.element.style.height = item.height;
|
|
89
|
+
});
|
|
90
|
+
delete window.__testivaiOriginalStyles;
|
|
91
|
+
}
|
|
92
|
+
`);
|
|
70
93
|
|
|
71
94
|
// 2. Dump full-page DOM
|
|
72
95
|
const domPath = path.join(outputDir, `${baseFilename}.html`);
|