@a11y-oracle/cypress-plugin 1.1.2 → 1.1.3
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/lib/commands.js +47 -0
- package/package.json +4 -4
package/dist/lib/commands.js
CHANGED
|
@@ -37,6 +37,7 @@ let engine = null;
|
|
|
37
37
|
let orchestrator = null;
|
|
38
38
|
let autFrameId = null;
|
|
39
39
|
let autContextId = null;
|
|
40
|
+
let autIframeBounds = null;
|
|
40
41
|
/**
|
|
41
42
|
* Send a raw CDP command through Cypress's automation channel.
|
|
42
43
|
*/
|
|
@@ -69,6 +70,21 @@ function createFrameAwareCDPAdapter() {
|
|
|
69
70
|
if (method === 'Runtime.evaluate' && autContextId !== null) {
|
|
70
71
|
p['contextId'] = autContextId;
|
|
71
72
|
}
|
|
73
|
+
// Translate iframe-relative clip coordinates to viewport coordinates.
|
|
74
|
+
// Runtime.evaluate runs inside the AUT iframe (via contextId), so
|
|
75
|
+
// getBoundingClientRect() returns iframe-relative coords. But
|
|
76
|
+
// Page.captureScreenshot clips relative to the top-level viewport.
|
|
77
|
+
if (method === 'Page.captureScreenshot' &&
|
|
78
|
+
p['clip'] &&
|
|
79
|
+
autIframeBounds &&
|
|
80
|
+
(autIframeBounds.x !== 0 || autIframeBounds.y !== 0)) {
|
|
81
|
+
const clip = p['clip'];
|
|
82
|
+
p['clip'] = {
|
|
83
|
+
...clip,
|
|
84
|
+
x: clip.x + autIframeBounds.x,
|
|
85
|
+
y: clip.y + autIframeBounds.y,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
72
88
|
return sendCDP(method, p);
|
|
73
89
|
},
|
|
74
90
|
};
|
|
@@ -122,6 +138,34 @@ async function findAUTContextId(frameId) {
|
|
|
122
138
|
return null;
|
|
123
139
|
}
|
|
124
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Get the AUT iframe's position in the top-level viewport.
|
|
143
|
+
*
|
|
144
|
+
* Runs `Runtime.evaluate` in the top-level context (without `contextId`)
|
|
145
|
+
* to find the AUT iframe and return its bounding rect origin. Adds
|
|
146
|
+
* `clientLeft`/`clientTop` to account for any iframe border.
|
|
147
|
+
*
|
|
148
|
+
* Used to translate iframe-relative coordinates from
|
|
149
|
+
* `getBoundingClientRect()` to viewport-absolute coordinates for
|
|
150
|
+
* `Page.captureScreenshot` clips.
|
|
151
|
+
*/
|
|
152
|
+
async function getAUTIframeBounds() {
|
|
153
|
+
const result = (await sendCDP('Runtime.evaluate', {
|
|
154
|
+
expression: `(() => {
|
|
155
|
+
const iframes = document.querySelectorAll('iframe');
|
|
156
|
+
for (const f of iframes) {
|
|
157
|
+
const src = f.getAttribute('src') || f.src || '';
|
|
158
|
+
if (src && !src.includes('/__/') && !src.includes('__cypress') && src !== 'about:blank') {
|
|
159
|
+
const rect = f.getBoundingClientRect();
|
|
160
|
+
return { x: rect.x + f.clientLeft, y: rect.y + f.clientTop };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return { x: 0, y: 0 };
|
|
164
|
+
})()`,
|
|
165
|
+
returnByValue: true,
|
|
166
|
+
}));
|
|
167
|
+
return result.result.value;
|
|
168
|
+
}
|
|
125
169
|
/**
|
|
126
170
|
* Focus the AUT iframe element so that CDP keyboard events
|
|
127
171
|
* reach the AUT's content instead of the Cypress runner UI.
|
|
@@ -214,6 +258,8 @@ Cypress.Commands.add('initA11yOracle', (options) => {
|
|
|
214
258
|
}
|
|
215
259
|
// Get the AUT frame's execution context for Runtime.evaluate
|
|
216
260
|
autContextId = await findAUTContextId(autFrameId);
|
|
261
|
+
// Cache iframe bounds for screenshot coordinate translation
|
|
262
|
+
autIframeBounds = await getAUTIframeBounds();
|
|
217
263
|
// Focus the AUT iframe so key events reach it
|
|
218
264
|
await focusAUTFrame();
|
|
219
265
|
// Create the CDP adapter that routes to the AUT frame
|
|
@@ -358,6 +404,7 @@ Cypress.Commands.add('disposeA11yOracle', () => {
|
|
|
358
404
|
}
|
|
359
405
|
autFrameId = null;
|
|
360
406
|
autContextId = null;
|
|
407
|
+
autIframeBounds = null;
|
|
361
408
|
return null;
|
|
362
409
|
});
|
|
363
410
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a11y-oracle/cypress-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Cypress custom commands for accessibility speech assertions with iframe-aware CDP routing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "a11y-oracle",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"cypress": ">=12.0.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@a11y-oracle/core-engine": "1.1.
|
|
49
|
-
"@a11y-oracle/keyboard-engine": "1.1.
|
|
50
|
-
"@a11y-oracle/audit-formatter": "1.1.
|
|
48
|
+
"@a11y-oracle/core-engine": "1.1.3",
|
|
49
|
+
"@a11y-oracle/keyboard-engine": "1.1.3",
|
|
50
|
+
"@a11y-oracle/audit-formatter": "1.1.3",
|
|
51
51
|
"tslib": "^2.3.0"
|
|
52
52
|
}
|
|
53
53
|
}
|