testaro 8.2.0 → 8.4.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/README.md +2 -2
- package/commands.js +9 -0
- package/package.json +1 -1
- package/run.js +1 -0
- package/tests/attVal.js +45 -0
package/README.md
CHANGED
package/commands.js
CHANGED
|
@@ -152,6 +152,15 @@ exports.commands = {
|
|
|
152
152
|
]
|
|
153
153
|
},
|
|
154
154
|
tests: {
|
|
155
|
+
attVal: [
|
|
156
|
+
'Perform an attVal test',
|
|
157
|
+
{
|
|
158
|
+
attributeName: [true, 'string', 'hasLength', 'name of attribute'],
|
|
159
|
+
areLicit: [true, 'boolean', '', 'whether values are licit'],
|
|
160
|
+
values: [true, 'array', 'areStrings', 'values of attribute'],
|
|
161
|
+
withItems: [true, 'boolean', '', 'itemize']
|
|
162
|
+
}
|
|
163
|
+
],
|
|
155
164
|
axe: [
|
|
156
165
|
'Perform an Axe test',
|
|
157
166
|
{
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -32,6 +32,7 @@ const moves = {
|
|
|
32
32
|
const tests = {
|
|
33
33
|
alfa: 'alfa',
|
|
34
34
|
allHidden: 'page that is entirely or mostly hidden',
|
|
35
|
+
attVal: 'elements with attributes having illicit values',
|
|
35
36
|
axe: 'Axe',
|
|
36
37
|
bulk: 'count of visible elements',
|
|
37
38
|
continuum: 'Level Access Continuum, community edition',
|
package/tests/attVal.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
attVal
|
|
3
|
+
This test reports attributes with illicit values.
|
|
4
|
+
*/
|
|
5
|
+
exports.reporter = async (page, attributeName, areLicit, values, withItems) => {
|
|
6
|
+
// Identify the elements that have the specified attribute with illicit values.
|
|
7
|
+
const badAttributeData = await page.evaluate(
|
|
8
|
+
args => {
|
|
9
|
+
const attributeName = args[0];
|
|
10
|
+
const areLicit = args[1];
|
|
11
|
+
const values = args[2];
|
|
12
|
+
// Returns the text of an element.
|
|
13
|
+
const textOf = async (element, limit) => {
|
|
14
|
+
let text = element.textContent;
|
|
15
|
+
text = text.trim() || element.innerHTML;
|
|
16
|
+
return text.replace(/\s+/sg, ' ').replace(/<>&/g, '').slice(0, limit);
|
|
17
|
+
};
|
|
18
|
+
const attributeElements = Array.from(document.body.querySelectorAll(`[${attributeName}]`));
|
|
19
|
+
const badElements = attributeElements
|
|
20
|
+
.filter(el => {
|
|
21
|
+
const value = el.getAttribute(attributeName);
|
|
22
|
+
if (areLicit) {
|
|
23
|
+
return values.includes(value);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return ! values.includes(value);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const report = badElements.map(el => ({
|
|
30
|
+
tagName: el.tagName,
|
|
31
|
+
textStart: textOf(el, 70),
|
|
32
|
+
attributeValue: el.getAttribute(attributeName)
|
|
33
|
+
}));
|
|
34
|
+
return report;
|
|
35
|
+
},
|
|
36
|
+
[attributeName, areLicit, values]
|
|
37
|
+
);
|
|
38
|
+
const data = {
|
|
39
|
+
total: badAttributeData.length
|
|
40
|
+
};
|
|
41
|
+
if (withItems) {
|
|
42
|
+
data.items = badAttributeData;
|
|
43
|
+
}
|
|
44
|
+
return {result: data};
|
|
45
|
+
};
|