testaro 16.0.0 → 16.2.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.
- package/actSpecs.js +1 -1
- package/package.json +1 -1
- package/procs/visChange.js +112 -0
- package/testaro/hover.js +117 -374
- package/testaro/motion.js +43 -132
- package/validation/tests/jobs/hovInd.json +320 -0
- package/validation/tests/jobs/hover.json +89 -143
- package/validation/tests/jobs/motion.json +27 -18
- package/validation/tests/targets/hover/bad.html +10 -9
- package/validation/tests/targets/motion/bad.css +4 -3
- package/procs/getKeyNav.js +0 -40
- /package/validation/tests/targets/{hover → hovInd}/styleBad.html +0 -0
package/actSpecs.js
CHANGED
|
@@ -184,7 +184,7 @@ exports.actSpecs = {
|
|
|
184
184
|
'Perform Testaro tests',
|
|
185
185
|
{
|
|
186
186
|
withItems: [true, 'boolean', '', 'itemize'],
|
|
187
|
-
args: [false, 'object', 'areArrays', 'extra args (object; property names are rule IDs and values are arrays of additional argument values ({autocomplete: [["first name", "forename", "given name"], ["last name", "surname", "family name"], ["email"]], buttonMenu:
|
|
187
|
+
args: [false, 'object', 'areArrays', 'extra args (object; property names are rule IDs and values are arrays of additional argument values ({autocomplete: [["first name", "forename", "given name"], ["last name", "surname", "family name"], ["email"]], buttonMenu: [], focInd: [false, 250], hover: [20]}) by default'],
|
|
188
188
|
}
|
|
189
189
|
],
|
|
190
190
|
wave: [
|
package/package.json
CHANGED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
visChange
|
|
3
|
+
This procedure reports a change in the visible content of a page between two times, optionally
|
|
4
|
+
hovering over a locator-defined element immediately after the first time.
|
|
5
|
+
WARNING: This test uses the Playwright page.screenshot method, which produces incorrect results
|
|
6
|
+
when the browser type is chromium and is not implemented for the firefox browser type. The only
|
|
7
|
+
browser type usable with this test is webkit.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// IMPORTS
|
|
11
|
+
|
|
12
|
+
const pixelmatch = require('pixelmatch');
|
|
13
|
+
const {PNG} = require('pngjs');
|
|
14
|
+
|
|
15
|
+
// FUNCTIONS
|
|
16
|
+
|
|
17
|
+
// Creates and returns a screenshot.
|
|
18
|
+
const shoot = async (page, exclusion = null) => {
|
|
19
|
+
// Make a screenshot as a buffer.
|
|
20
|
+
const options = {
|
|
21
|
+
fullPage: true,
|
|
22
|
+
omitBackground: true,
|
|
23
|
+
timeout: 2000
|
|
24
|
+
};
|
|
25
|
+
if (exclusion) {
|
|
26
|
+
const exclusionText = await exclusion.textContent();
|
|
27
|
+
options.mask = [exclusion];
|
|
28
|
+
}
|
|
29
|
+
return await page.screenshot(options)
|
|
30
|
+
.catch(error => {
|
|
31
|
+
console.log(`ERROR: Screenshot failed (${error.message})`);
|
|
32
|
+
return '';
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.visChange = async (page, options = {}) => {
|
|
36
|
+
const {delayBefore, delayBetween, exclusion} = options;
|
|
37
|
+
// Wait, if required.
|
|
38
|
+
if (delayBefore) {
|
|
39
|
+
await page.waitForTimeout(delayBefore);
|
|
40
|
+
}
|
|
41
|
+
// If an exclusion was specified:
|
|
42
|
+
if (exclusion) {
|
|
43
|
+
// Hover over the upper-left corner of the page for test isolation.
|
|
44
|
+
const docLoc = page.locator('html');
|
|
45
|
+
await docLoc.hover({
|
|
46
|
+
position: {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// Make a screenshot, excluding an element if specified.
|
|
53
|
+
const shot0 = await shoot(page, exclusion);
|
|
54
|
+
// If it succeeded:
|
|
55
|
+
if (shot0.length) {
|
|
56
|
+
// If an exclusion was specified:
|
|
57
|
+
if (exclusion) {
|
|
58
|
+
// Hover over it.
|
|
59
|
+
try {
|
|
60
|
+
await exclusion.hover({
|
|
61
|
+
timeout: 500,
|
|
62
|
+
noWaitAfter: true
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch(error) {
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
error: 'Hovering failed'
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Wait as specified, or 3 seconds.
|
|
73
|
+
await page.waitForTimeout(delayBetween || 3000);
|
|
74
|
+
// Make another screenshot.
|
|
75
|
+
const shot1 = await shoot(page, exclusion);
|
|
76
|
+
// If it succeeded:
|
|
77
|
+
if (shot1.length) {
|
|
78
|
+
// Get the shots as PNG images.
|
|
79
|
+
const pngs = [shot0, shot1].map(shot => PNG.sync.read(shot));
|
|
80
|
+
// Get their dimensions.
|
|
81
|
+
const {width, height} = pngs[0];
|
|
82
|
+
// Get the count of differing pixels between the shots.
|
|
83
|
+
const pixelChanges = pixelmatch(pngs[0].data, pngs[1].data, null, width, height);
|
|
84
|
+
// Get the ratio of differing to all pixels as a percentage.
|
|
85
|
+
const changePercent = 100 * pixelChanges / (width * height);
|
|
86
|
+
// Return this.
|
|
87
|
+
return {
|
|
88
|
+
success: true,
|
|
89
|
+
width,
|
|
90
|
+
height,
|
|
91
|
+
pixelChanges,
|
|
92
|
+
changePercent
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Otherwise, i.e. if the second screenshot failed:
|
|
96
|
+
else {
|
|
97
|
+
// Return this.
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
error: 'Second screenshot failed'
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Otherwise, i.e. if the screenshot failed:
|
|
105
|
+
else {
|
|
106
|
+
// Return this.
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
error: 'First screenshot failed'
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|