@empiricalrun/test-gen 0.38.7 → 0.38.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/CHANGELOG.md
CHANGED
|
@@ -24,6 +24,8 @@ function annotateClickableElements(options = {}) {
|
|
|
24
24
|
// Check if the element is not blocked and visible for clicking
|
|
25
25
|
function isElementClickNotBlocked(element, windowToAnnotate) {
|
|
26
26
|
const rect = element.getBoundingClientRect();
|
|
27
|
+
const originalScrollX = windowToAnnotate.scrollX;
|
|
28
|
+
const originalScrollY = windowToAnnotate.scrollY;
|
|
27
29
|
|
|
28
30
|
// Calculate the center point of the element
|
|
29
31
|
const centerX = rect.left + rect.width / 2;
|
|
@@ -56,7 +58,12 @@ function annotateClickableElements(options = {}) {
|
|
|
56
58
|
const newCenterX = newRect.left + newRect.width / 2;
|
|
57
59
|
const newCenterY = newRect.top + newRect.height / 2;
|
|
58
60
|
const topElement = document.elementFromPoint(newCenterX, newCenterY);
|
|
59
|
-
|
|
61
|
+
const doesElementContainTopElement = element.contains(topElement);
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// Restore the original scroll positions
|
|
65
|
+
windowToAnnotate.scrollTo(originalScrollX, originalScrollY);
|
|
66
|
+
return doesElementContainTopElement;
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
const topElement = windowToAnnotate.document.elementFromPoint(centerX, centerY);
|
|
@@ -306,20 +313,18 @@ function annotateClickableElements(options = {}) {
|
|
|
306
313
|
var parentElements = [];
|
|
307
314
|
|
|
308
315
|
// Create a hint marker
|
|
309
|
-
function createHintMarker(el, hint, parentElement) {
|
|
316
|
+
function createHintMarker(el, hint, parentElement, windowToAnnotate) {
|
|
310
317
|
const rect = el.getBoundingClientRect();
|
|
311
|
-
const parentRect = parentElement.getBoundingClientRect();
|
|
312
318
|
|
|
313
319
|
// Create the marker element
|
|
314
320
|
const marker = document.createElement("div");
|
|
315
321
|
marker.textContent = hint;
|
|
316
322
|
marker.className = markerClass;
|
|
317
|
-
|
|
318
323
|
// Style the marker
|
|
319
324
|
Object.assign(marker.style, {
|
|
320
325
|
position: "absolute",
|
|
321
|
-
top: `${rect.top +
|
|
322
|
-
left: `${rect.left +
|
|
326
|
+
top: `${rect.top + windowToAnnotate.scrollY}px`,
|
|
327
|
+
left: `${rect.left + windowToAnnotate.scrollX}px`,
|
|
323
328
|
background:
|
|
324
329
|
"-webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 247, 133)), to(rgb(255, 197, 66)))",
|
|
325
330
|
padding: "1px 3px 0px",
|
|
@@ -369,7 +374,9 @@ function annotateClickableElements(options = {}) {
|
|
|
369
374
|
|
|
370
375
|
// Filter for clickable elements
|
|
371
376
|
const clickableElements = Array.from(windowToAnnotate.document.querySelectorAll("*")).filter((el) => {
|
|
372
|
-
|
|
377
|
+
const isClickable = isElementClickable(el);
|
|
378
|
+
const isClickNotBlocked = isElementClickNotBlocked(el, windowToAnnotate);
|
|
379
|
+
return isClickable && isClickNotBlocked;
|
|
373
380
|
});
|
|
374
381
|
// Generate hint strings for the clickable elements
|
|
375
382
|
const hints = generateHintStrings(hintCharacterSet, Math.min(maxHints, clickableElements.length));
|
|
@@ -380,7 +387,7 @@ function annotateClickableElements(options = {}) {
|
|
|
380
387
|
const rect = el.getBoundingClientRect();
|
|
381
388
|
|
|
382
389
|
// Use createHintMarker with the specified container
|
|
383
|
-
createHintMarker(el, hint, container);
|
|
390
|
+
createHintMarker(el, hint, container, windowToAnnotate);
|
|
384
391
|
el.style.boxShadow = `inset 0 0 0px 2px red`;
|
|
385
392
|
|
|
386
393
|
// Add element details to the annotations map
|
|
@@ -24,6 +24,8 @@ function annotateClickableElements(options = {}) {
|
|
|
24
24
|
// Check if the element is not blocked and visible for clicking
|
|
25
25
|
function isElementClickNotBlocked(element, windowToAnnotate) {
|
|
26
26
|
const rect = element.getBoundingClientRect();
|
|
27
|
+
const originalScrollX = windowToAnnotate.scrollX;
|
|
28
|
+
const originalScrollY = windowToAnnotate.scrollY;
|
|
27
29
|
|
|
28
30
|
// Calculate the center point of the element
|
|
29
31
|
const centerX = rect.left + rect.width / 2;
|
|
@@ -56,7 +58,12 @@ function annotateClickableElements(options = {}) {
|
|
|
56
58
|
const newCenterX = newRect.left + newRect.width / 2;
|
|
57
59
|
const newCenterY = newRect.top + newRect.height / 2;
|
|
58
60
|
const topElement = document.elementFromPoint(newCenterX, newCenterY);
|
|
59
|
-
|
|
61
|
+
const doesElementContainTopElement = element.contains(topElement);
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// Restore the original scroll positions
|
|
65
|
+
windowToAnnotate.scrollTo(originalScrollX, originalScrollY);
|
|
66
|
+
return doesElementContainTopElement;
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
const topElement = windowToAnnotate.document.elementFromPoint(centerX, centerY);
|
|
@@ -306,20 +313,18 @@ function annotateClickableElements(options = {}) {
|
|
|
306
313
|
var parentElements = [];
|
|
307
314
|
|
|
308
315
|
// Create a hint marker
|
|
309
|
-
function createHintMarker(el, hint, parentElement) {
|
|
316
|
+
function createHintMarker(el, hint, parentElement, windowToAnnotate) {
|
|
310
317
|
const rect = el.getBoundingClientRect();
|
|
311
|
-
const parentRect = parentElement.getBoundingClientRect();
|
|
312
318
|
|
|
313
319
|
// Create the marker element
|
|
314
320
|
const marker = document.createElement("div");
|
|
315
321
|
marker.textContent = hint;
|
|
316
322
|
marker.className = markerClass;
|
|
317
|
-
|
|
318
323
|
// Style the marker
|
|
319
324
|
Object.assign(marker.style, {
|
|
320
325
|
position: "absolute",
|
|
321
|
-
top: `${rect.top +
|
|
322
|
-
left: `${rect.left +
|
|
326
|
+
top: `${rect.top + windowToAnnotate.scrollY}px`,
|
|
327
|
+
left: `${rect.left + windowToAnnotate.scrollX}px`,
|
|
323
328
|
background:
|
|
324
329
|
"-webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 247, 133)), to(rgb(255, 197, 66)))",
|
|
325
330
|
padding: "1px 3px 0px",
|
|
@@ -369,7 +374,9 @@ function annotateClickableElements(options = {}) {
|
|
|
369
374
|
|
|
370
375
|
// Filter for clickable elements
|
|
371
376
|
const clickableElements = Array.from(windowToAnnotate.document.querySelectorAll("*")).filter((el) => {
|
|
372
|
-
|
|
377
|
+
const isClickable = isElementClickable(el);
|
|
378
|
+
const isClickNotBlocked = isElementClickNotBlocked(el, windowToAnnotate);
|
|
379
|
+
return isClickable && isClickNotBlocked;
|
|
373
380
|
});
|
|
374
381
|
// Generate hint strings for the clickable elements
|
|
375
382
|
const hints = generateHintStrings(hintCharacterSet, Math.min(maxHints, clickableElements.length));
|
|
@@ -380,7 +387,7 @@ function annotateClickableElements(options = {}) {
|
|
|
380
387
|
const rect = el.getBoundingClientRect();
|
|
381
388
|
|
|
382
389
|
// Use createHintMarker with the specified container
|
|
383
|
-
createHintMarker(el, hint, container);
|
|
390
|
+
createHintMarker(el, hint, container, windowToAnnotate);
|
|
384
391
|
el.style.boxShadow = `inset 0 0 0px 2px red`;
|
|
385
392
|
|
|
386
393
|
// Add element details to the annotations map
|