testaro 60.11.0 → 60.13.0

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.
@@ -0,0 +1,110 @@
1
+ /*
2
+ © 2021–2024 CVS Health and/or one of its affiliates. All rights reserved.
3
+ © 2025 Jonathan Robert Pool. All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ */
25
+
26
+ /*
27
+ hover
28
+ This test reports unexpected impacts of hovering. The elements that are subjected to hovering
29
+ (called “triggers”) include all the elements that have ARIA attributes associated with control
30
+ over the visibility of other elements and all the elements that have onmouseenter or
31
+ onmouseover attributes, as well as a sample of all visible elements in the body. If hovering over
32
+ an element results in an increase or decrease in the total count of visible elements in the body,
33
+ the rule is considered violated.
34
+ */
35
+
36
+ // IMPORTS
37
+
38
+ const {doTest} = require('../procs/testaro');
39
+
40
+ // FUNCTIONS
41
+
42
+ exports.reporter = async (page, withItems) => {
43
+ const getBadWhat = element => {
44
+ let violationDescription;
45
+ const hoverEvent = new MouseEvent('mouseover', {
46
+ bubbles: true,
47
+ cancelable: true,
48
+ view: window
49
+ });
50
+ let timer;
51
+ // Create a mutation observer.
52
+ const observer = new MutationObserver(mutations => {
53
+ // When any mutation occurs in any other element(s):
54
+ const otherMutatedRecords = mutations.filter(
55
+ record => record.target !== element && record.target.getAttribute('role') !== 'tooltip'
56
+ );
57
+ // Update the count of mutated elements and the violation description.
58
+ const impactCount = otherMutatedRecords.length;
59
+ const impactWhat = impactCount === 1 ? '1 other element1' : `${impactCount} other elements`;
60
+ violationDescription = `Hovering over the element adds, removes, or changes ${impactWhat}`;
61
+ // Stop the observer.
62
+ observer.disconnect();
63
+ // Clear the timer.
64
+ clearTimeout(timer);
65
+ });
66
+ // Ensure that the mouse is in the home position.
67
+ document.body.dispatchEvent(hoverEvent);
68
+ // Start observing.
69
+ observer.observe(document.body, {
70
+ attributes: true,
71
+ subtree: true,
72
+ childList: true
73
+ });
74
+ // Start hovering over the element.
75
+ element.dispatchEvent(hoverEvent);
76
+ // In case no other elements were mutated within 200ms, stop the observer.
77
+ timer = setTimeout(() => {
78
+ observer.disconnect();
79
+ }, 200);
80
+ // If any other elements were mutated within 200ms:
81
+ if (violationDescription) {
82
+ // Return the violation description.
83
+ return violationDescription;
84
+ }
85
+ };
86
+ const selector = [
87
+ '[aria-controls]',
88
+ '[aria-expanded]',
89
+ '[aria-haspopup]',
90
+ '[onmouseenter]',
91
+ '[onmouseover]',
92
+ '[onmouseenter]',
93
+ '[onmouseover]',
94
+ '[role="menu"]',
95
+ '[role="menubar"]',
96
+ '[role="menuitem"]',
97
+ '[data-tooltip]',
98
+ '[data-popover]',
99
+ '[data-hover]',
100
+ '[data-menu]',
101
+ '[data-dropdown]',
102
+ '[role="tab"]',
103
+ '[role="combobox"]',
104
+ 'li'
105
+ ].join(', ');
106
+ const whats = 'Hovering over elements adds, removes, or changes other elements';
107
+ return await doTest(
108
+ page, withItems, 'hover', selector, whats, 0, '', getBadWhat.toString()
109
+ );
110
+ };
@@ -0,0 +1,185 @@
1
+ /*
2
+ © 2021–2024 CVS Health and/or one of its affiliates. All rights reserved.
3
+ © 2025 Jonathan Robert Pool. All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ */
25
+
26
+ /*
27
+ hover
28
+ This test reports unexpected impacts of hovering. The elements that are subjected to hovering
29
+ (called “triggers”) include all the elements that have ARIA attributes associated with control
30
+ over the visibility of other elements and all the elements that have onmouseenter or
31
+ onmouseover attributes, as well as a sample of all visible elements in the body. If hovering over
32
+ an element results in an increase or decrease in the total count of visible elements in the body,
33
+ the rule is considered violated.
34
+ */
35
+
36
+ // IMPORTS
37
+
38
+ const {doTest} = require('../procs/testaro');
39
+
40
+ // FUNCTIONS
41
+
42
+ exports.reporter = async (page, withItems) => {
43
+ const getBadWhat = async element => {
44
+ const isVisible = element.checkVisibility({
45
+ contentVisibilityAuto: true,
46
+ opacityProperty: true,
47
+ visibilityProperty: true
48
+ });
49
+ // If the element is visible and is not a tooltip:
50
+ if (isVisible && element.getAttribute('role') !== 'tooltip') {
51
+ let timer;
52
+ let observer;
53
+ const options = {
54
+ bubbles: true,
55
+ cancelable: true,
56
+ view: window
57
+ };
58
+ const hoverEvents = [
59
+ new MouseEvent('mouseover', options),
60
+ new MouseEvent('mousemove', options),
61
+ new PointerEvent('pointerover', options),
62
+ new PointerEvent('pointermove', options)
63
+ ];
64
+ const {__lastHoveredElement} = window;
65
+ // Exit the prior hover location, if any.
66
+ if (__lastHoveredElement) {
67
+ [
68
+ [MouseEvent, 'mouseout', true],
69
+ [MouseEvent, 'mouseleave', false],
70
+ [PointerEvent, 'pointerout', true],
71
+ [PointerEvent, 'pointerleave', false]
72
+ ].forEach(([event, type, bubbles]) => {
73
+ __lastHoveredElement.dispatchEvent(new event(type, {bubbles}));
74
+ });
75
+ }
76
+ // Allow time for handlers of these events to complete execution.
77
+ await new Promise(resolve => setTimeout(resolve, 800));
78
+ // Check whether the visibility of the element was due solely to the prior hovering.
79
+ const isStillVisible = element.checkVisibility({
80
+ contentVisibilityAuto: true,
81
+ opacityProperty: true,
82
+ visibilityProperty: true
83
+ });
84
+ // If so:
85
+ if (isStillVisible) {
86
+ const observationStart = Date.now();
87
+ // Execute a Promise that resolves when a mutation is observed.
88
+ const mutationPromise = new Promise(resolve => {
89
+ // When mutations are observed:
90
+ observer = new MutationObserver(mutationRecords => {
91
+ const otherMutationRecords = mutationRecords.filter(record => {
92
+ const {target, type} = record;
93
+ return type !== 'childList'
94
+ && target !== element
95
+ && target.getAttribute('role') !== 'tooltip';
96
+ });
97
+ // If any are reportable:
98
+ if (otherMutationRecords.length) {
99
+ // Get a non-duplicative set of their types and XPaths.
100
+ const impacts = new Set();
101
+ otherMutationRecords.forEach(record => {
102
+ const {attributeName, target, type} = record;
103
+ const xPath = getXPath(target);
104
+ const attributeSuffix = attributeName ? `:${attributeName}` : '';
105
+ const textStart = target.textContent?.slice(0, 20).trim().replace(/\s+/g, ' ') || '';
106
+ impacts.add(`${type}${attributeSuffix}@${xPath} (“${textStart}”)`);
107
+ });
108
+ const impactTime = Math.round(Date.now() - observationStart);
109
+ // Create a violation description with the elapsed time and the mutation details.
110
+ const violationWhat = `Hovering over the element makes these changes after ${impactTime}ms: ${Array.from(impacts).join(', ')}`;
111
+ // Clear the timer.
112
+ clearTimeout(timer);
113
+ // Stop the observer.
114
+ observer.disconnect();
115
+ // Resolve the Promise with the violation description.
116
+ resolve(violationWhat);
117
+ }
118
+ });
119
+ let observationRoot = element.parentElement.parentElement;
120
+ const rootTagName = observationRoot.tagName;
121
+ if (['MAIN', 'BODY'].includes(rootTagName)) {
122
+ observationRoot = element.parentElement;
123
+ }
124
+ // Start observing.
125
+ observer.observe(observationRoot, {
126
+ attributes: true,
127
+ attributeFilter: ['style', 'class', 'hidden', 'aria-hidden', 'disabled', 'open'],
128
+ subtree: true,
129
+ childList: true
130
+ });
131
+ // Start hovering over the element.
132
+ hoverEvents.forEach(event => {
133
+ element.dispatchEvent(event);
134
+ });
135
+ // Record the element for future mouseout events.
136
+ window.__lastHoveredElement = element;
137
+ });
138
+ // Execute a Promise that resolves when a time limit expires.
139
+ const timeoutPromise = new Promise(resolve => {
140
+ // If no mutation is observed before the time limit:
141
+ timer = setTimeout(() => {
142
+ // Stop the observer.
143
+ observer.disconnect();
144
+ // Resolve the Promise with an empty string.
145
+ resolve('');
146
+ }, 400);
147
+ });
148
+ // Get the violation description or timeout report.
149
+ const violationWhat = await Promise.race([mutationPromise, timeoutPromise]);
150
+ // If any mutations occurred before the time limit:
151
+ if (violationWhat) {
152
+ // Return the violation description.
153
+ return violationWhat;
154
+ }
155
+ //XXX Temp
156
+ return 'No mutations';
157
+ }
158
+ }
159
+ };
160
+ const selector = [
161
+ '[aria-controls]',
162
+ '[aria-expanded]',
163
+ '[aria-haspopup]',
164
+ '[onmouseenter]',
165
+ '[onmouseover]',
166
+ '[onmouseenter]',
167
+ '[onmouseover]',
168
+ '[role="menu"]',
169
+ '[role="menubar"]',
170
+ '[role="menuitem"]',
171
+ '[data-tooltip]',
172
+ '[data-popover]',
173
+ '[data-hover]',
174
+ '[data-menu]',
175
+ '[data-dropdown]',
176
+ '[role="tab"]',
177
+ '[role="combobox"]',
178
+ 'a',
179
+ 'button'
180
+ ].join(', ');
181
+ const whats = 'Hovering over elements adds, removes, or changes other elements';
182
+ return await doTest(
183
+ page, withItems, 'hover', selector, whats, 0, '', getBadWhat.toString()
184
+ );
185
+ };
@@ -0,0 +1,183 @@
1
+ /*
2
+ © 2021–2024 CVS Health and/or one of its affiliates. All rights reserved.
3
+ © 2025 Jonathan Robert Pool. All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ */
25
+
26
+ /*
27
+ hover
28
+ This test reports unexpected impacts of hovering over owning or controlling elements. The
29
+ elements that are subjected to hovering (called “triggers”) include the elements that have
30
+ attributes associated with control over the visibility of other elements. If hovering over an
31
+ element results in a change in the count or particular attributes of elements other than the
32
+ trigger within the tree rooted at the grandparent of the trigger, the rule is considered violated.
33
+ The times allowed for the settling of handlers of mouse and pointer events (30ms and 200ms) have
34
+ been derived from empirical testing but may need to be revised after more experience.
35
+ */
36
+
37
+ // IMPORTS
38
+
39
+ const {doTest} = require('../procs/testaro');
40
+
41
+ // FUNCTIONS
42
+
43
+ exports.reporter = async (page, withItems) => {
44
+ const getBadWhat = async element => {
45
+ const isVisible = element.checkVisibility({
46
+ contentVisibilityAuto: true,
47
+ opacityProperty: true,
48
+ visibilityProperty: true
49
+ });
50
+ // If the element is visible and is not a tooltip:
51
+ if (isVisible && element.getAttribute('role') !== 'tooltip') {
52
+ let timer;
53
+ let observer;
54
+ const options = {
55
+ bubbles: true,
56
+ cancelable: true,
57
+ view: window
58
+ };
59
+ const hoverEvents = [
60
+ new MouseEvent('mouseover', options),
61
+ new MouseEvent('mousemove', options),
62
+ new PointerEvent('pointerover', options),
63
+ new PointerEvent('pointermove', options)
64
+ ];
65
+ const {__lastHoveredElement} = window;
66
+ // Exit the prior hover location, if any.
67
+ if (__lastHoveredElement) {
68
+ [
69
+ [MouseEvent, 'mouseout', true],
70
+ [MouseEvent, 'mouseleave', false],
71
+ [PointerEvent, 'pointerout', true],
72
+ [PointerEvent, 'pointerleave', false]
73
+ ].forEach(([event, type, bubbles]) => {
74
+ __lastHoveredElement.dispatchEvent(new event(type, {bubbles}));
75
+ });
76
+ }
77
+ // Allow time for handlers of these events to complete execution.
78
+ await new Promise(resolve => setTimeout(resolve, 30));
79
+ // Check whether the visibility of the element was due solely to the prior hovering.
80
+ const isStillVisible = element.checkVisibility({
81
+ contentVisibilityAuto: true,
82
+ opacityProperty: true,
83
+ visibilityProperty: true
84
+ });
85
+ // If so:
86
+ if (isStillVisible) {
87
+ const observationStart = Date.now();
88
+ // Execute a Promise that resolves when a mutation is observed.
89
+ const mutationPromise = new Promise(resolve => {
90
+ // When mutations are observed:
91
+ observer = new MutationObserver(mutationRecords => {
92
+ const otherMutationRecords = mutationRecords.filter(record => {
93
+ const {target, type} = record;
94
+ return type !== 'childList'
95
+ && target !== element
96
+ && target.getAttribute('role') !== 'tooltip';
97
+ });
98
+ // If any are reportable:
99
+ if (otherMutationRecords.length) {
100
+ // Get a non-duplicative set of their types and XPaths.
101
+ const impacts = new Set();
102
+ otherMutationRecords.forEach(record => {
103
+ const {attributeName, target, type} = record;
104
+ const xPath = getXPath(target);
105
+ const attributeSuffix = attributeName ? `:${attributeName}` : '';
106
+ const textStart = target.textContent?.slice(0, 20).trim().replace(/\s+/g, ' ') || '';
107
+ impacts.add(`${type}${attributeSuffix}@${xPath} (“${textStart}”)`);
108
+ });
109
+ const impactTime = Math.round(Date.now() - observationStart);
110
+ // Create a violation description with the elapsed time and the mutation details.
111
+ const violationWhat = `Hovering over the element makes these changes after ${impactTime}ms: ${Array.from(impacts).join(', ')}`;
112
+ // Clear the timer.
113
+ clearTimeout(timer);
114
+ // Stop the observer.
115
+ observer.disconnect();
116
+ // Resolve the Promise with the violation description.
117
+ resolve(violationWhat);
118
+ }
119
+ });
120
+ let observationRoot = element.parentElement.parentElement;
121
+ const rootTagName = observationRoot.tagName;
122
+ if (['MAIN', 'BODY'].includes(rootTagName)) {
123
+ observationRoot = element.parentElement;
124
+ }
125
+ // Start observing.
126
+ observer.observe(observationRoot, {
127
+ attributes: true,
128
+ attributeFilter: ['style', 'class', 'hidden', 'aria-hidden', 'disabled', 'open'],
129
+ subtree: true,
130
+ childList: true
131
+ });
132
+ // Start hovering over the element.
133
+ hoverEvents.forEach(event => {
134
+ element.dispatchEvent(event);
135
+ });
136
+ // Record the element for future mouseout events.
137
+ window.__lastHoveredElement = element;
138
+ });
139
+ // Execute a Promise that resolves when a time limit expires.
140
+ const timeoutPromise = new Promise(resolve => {
141
+ // If no mutation is observed before the time limit:
142
+ timer = setTimeout(() => {
143
+ // Stop the observer.
144
+ observer.disconnect();
145
+ // Resolve the Promise with an empty string.
146
+ resolve('');
147
+ }, 200);
148
+ });
149
+ // Get the violation description or timeout report.
150
+ const violationWhat = await Promise.race([mutationPromise, timeoutPromise]);
151
+ // If any mutations occurred before the time limit:
152
+ if (violationWhat) {
153
+ // Return the violation description.
154
+ return violationWhat;
155
+ }
156
+ return 'No mutations';
157
+ }
158
+ }
159
+ };
160
+ const selector = [
161
+ '[aria-controls]',
162
+ '[aria-expanded]',
163
+ '[aria-haspopup]',
164
+ '[onmouseenter]',
165
+ '[onmouseover]',
166
+ '[onpointerenter]',
167
+ '[onpointerover]',
168
+ '[role="menu"]',
169
+ '[role="menubar"]',
170
+ '[role="menuitem"]',
171
+ '[data-tooltip]',
172
+ '[data-popover]',
173
+ '[data-hover]',
174
+ '[data-menu]',
175
+ '[data-dropdown]',
176
+ '[role="tab"]',
177
+ '[role="combobox"]'
178
+ ].join(', ');
179
+ const whats = 'Hovering over elements adds, removes, or changes other elements';
180
+ return await doTest(
181
+ page, withItems, 'hover', selector, whats, 0, '', getBadWhat.toString()
182
+ );
183
+ };
@@ -0,0 +1,143 @@
1
+ /*
2
+ © 2021–2024 CVS Health and/or one of its affiliates. All rights reserved.
3
+ © 2025 Jonathan Robert Pool. All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ */
25
+
26
+ /*
27
+ hover
28
+ This test reports unexpected impacts of hovering. The elements that are subjected to hovering
29
+ (called “triggers”) include all the elements that have attributes associated with control over
30
+ the visibility of other elements. If hovering over an element results in an increase or decrease
31
+ in the total count of visible elements in the tree rooted in the grandparent of the trigger,
32
+ the rule is considered violated.
33
+ */
34
+
35
+ // ########## IMPORTS
36
+
37
+ // Module to perform common operations.
38
+ const {getRuleResult} = require('../procs/testaro');
39
+
40
+ // ########## FUNCTIONS
41
+
42
+ // Runs the test and returns the result.
43
+ exports.reporter = async (page, withItems) => {
44
+ // Initialize the locators and result.
45
+ const candidateLocs = await page.locator([
46
+ '[aria-controls]:visible',
47
+ '[aria-expanded]:visible',
48
+ '[aria-haspopup]:visible',
49
+ '[onmouseenter]:visible',
50
+ '[onmouseover]:visible',
51
+ '[onpointerenter]:visible',
52
+ '[onpointerover]:visible',
53
+ '[role="menu"]:visible',
54
+ '[role="menubar"]:visible',
55
+ '[role="menuitem"]:visible',
56
+ '[data-tooltip]:visible',
57
+ '[data-popover]:visible',
58
+ '[data-hover]:visible',
59
+ '[data-menu]:visible',
60
+ '[data-dropdown]:visible',
61
+ '[role="tab"]:visible',
62
+ '[role="combobox"]:visible'
63
+ ].join(', '));
64
+ const allLocs = await candidateLocs.all();
65
+ const all = {
66
+ allLocs,
67
+ locs: [],
68
+ result: {
69
+ data: {
70
+ populationRatio: 1
71
+ },
72
+ totals: [0, 0, 0, 0],
73
+ standardInstances: []
74
+ }
75
+ };
76
+ // For each locator:
77
+ for (const loc of allLocs) {
78
+ // Move the mouse to the top left corner of the page.
79
+ await page.mouse.move(0, 0);
80
+ // Get the XPath of the element referenced by the locator.
81
+ let xPath = await loc.evaluate(element => getXPath(element));
82
+ // Change it to the XPath of the desired observation root.
83
+ const pathSegments = xPath.split('/');
84
+ const {length} = pathSegments;
85
+ pathSegments.pop();
86
+ if (! ['main', 'body'].includes(pathSegments[length - 2])) {
87
+ pathSegments.pop();
88
+ }
89
+ xPath = pathSegments.join('/');
90
+ const rootLoc = page.locator(`xpath=${xPath}`);
91
+ // Get a count of the visible elements in the observation tree.
92
+ const loc0 = await rootLoc.locator('*:visible');
93
+ const elementCount0 = await loc0.count();
94
+ try {
95
+ // Hover over the element.
96
+ await loc.hover({timeout: 400});
97
+ // Get a count of the visible elements in the observation tree.
98
+ const loc1 = await rootLoc.locator('*:visible');
99
+ const elementCount1 = await loc1.count();
100
+ // Stop hovering over the element.
101
+ await page.mouse.move(0, 0);
102
+ let timeoutTimer;
103
+ let settleInterval;
104
+ const timeoutPromise = new Promise(resolve => {
105
+ timeoutTimer = setTimeout(() => {
106
+ clearTimeout(settleInterval);
107
+ resolve();
108
+ });
109
+ }, 400);
110
+ settlePromise = new Promise(resolve => {
111
+ settleInterval = setInterval(async () => {
112
+ const elementCount2 = await loc1.count();
113
+ if (elementCount2 < elementCount1) {
114
+ clearTimeout(timeoutTimer);
115
+ clearInterval(settleInterval);
116
+ resolve();
117
+ }
118
+ });
119
+ }, 75);
120
+ await Promise.race([timeoutPromise, settlePromise]);
121
+ // If the count has changed:
122
+ if (elementCount1 !== elementCount0) {
123
+ // Add the locator and a violation description to the array of violation locators.
124
+ const impact = elementCount1 - elementCount0;
125
+ all.locs.push([loc, impact]);
126
+ }
127
+ }
128
+ // If hovering times out:
129
+ catch(error) {
130
+ // Report the test prevented.
131
+ const {data} = all.result;
132
+ data.prevented = true;
133
+ data.error = 'ERROR hovering over an element';
134
+ break;
135
+ }
136
+ }
137
+ // Populate and return the result.
138
+ const whats = [
139
+ 'Hovering over the element changes the number of elements on the page by __param__',
140
+ 'Hovering over elements changes the number of elements on the page'
141
+ ];
142
+ return await getRuleResult(withItems, all, 'hover', whats, 0);
143
+ };