testaro 4.10.2 → 4.11.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/commands.js CHANGED
@@ -153,7 +153,7 @@ exports.commands = {
153
153
  axe: [
154
154
  'Perform an Axe test',
155
155
  {
156
- withItems: [true, 'boolean'],
156
+ detailLevel: [true, 'number', '', 'count to include of: violations, incomplete, passes, inapplicable'],
157
157
  rules: [true, 'array', 'areStrings', 'rule names, or empty if all']
158
158
  }
159
159
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "4.10.2",
3
+ "version": "4.11.0",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -64,10 +64,25 @@ const tenonData = {
64
64
  accessToken: '',
65
65
  requestIDs: {}
66
66
  };
67
+ // Keywords in log messages indicating errors.
68
+ const errorWords = [
69
+ 'failed',
70
+ 'error',
71
+ 'suspicious',
72
+ 'refused',
73
+ 'content security policy',
74
+ 'unrecognized',
75
+ 'requires',
76
+ 'warning',
77
+ 'missing',
78
+ 'deprecated'
79
+ ];
67
80
  // ########## VARIABLES
68
81
  // Facts about the current session.
69
82
  let logCount = 0;
70
83
  let logSize = 0;
84
+ let errorLogCount = 0;
85
+ let errorLogSize = 0;
71
86
  let prohibitedCount = 0;
72
87
  let visitTimeoutCount = 0;
73
88
  let visitRejectionCount = 0;
@@ -253,12 +268,18 @@ const launch = async typeName => {
253
268
  browserContext = await browser.newContext(viewport);
254
269
  // When a page is added to the browser context:
255
270
  browserContext.on('page', page => {
256
- // Make its console messages appear in the Playwright console.
271
+ // Make its console messages get reported and appear in the Playwright console.
257
272
  page.on('console', msg => {
258
273
  const msgText = msg.text();
259
274
  console.log(`[${msgText}]`);
275
+ const msgTextLC = msgText.toLowerCase();
276
+ const msgLength = msgText.length;
260
277
  logCount++;
261
- logSize += msgText.length;
278
+ logSize += msgLength;
279
+ if (errorWords.some(word => msgTextLC.includes(word))) {
280
+ errorLogCount++;
281
+ errorLogSize += msgLength;
282
+ }
262
283
  const msgLC = msgText.toLowerCase();
263
284
  if (msgText.includes('403') && (msgLC.includes('status') || msgLC.includes('prohibited'))) {
264
285
  prohibitedCount++;
@@ -1224,7 +1245,13 @@ const doActs = async (report, actIndex, page) => {
1224
1245
  // Performs the commands in a script.
1225
1246
  const doScript = async (report) => {
1226
1247
  // Reinitialize the log statistics.
1227
- logCount = logSize = prohibitedCount = visitTimeoutCount = visitRejectionCount= 0;
1248
+ logCount = 0;
1249
+ logSize = 0;
1250
+ errorLogCount = 0;
1251
+ errorLogSize = 0;
1252
+ prohibitedCount = 0;
1253
+ visitTimeoutCount = 0;
1254
+ visitRejectionCount = 0;
1228
1255
  // Add the start time to the report.
1229
1256
  const startTime = new Date();
1230
1257
  report.startTime = startTime.toISOString().slice(0, 19);
@@ -1239,6 +1266,8 @@ const doScript = async (report) => {
1239
1266
  // Add the log statistics to the report.
1240
1267
  report.logCount = logCount;
1241
1268
  report.logSize = logSize;
1269
+ report.errorLogCount = errorLogCount;
1270
+ report.errorLogSize = errorLogSize;
1242
1271
  report.prohibitedCount = prohibitedCount;
1243
1272
  report.visitTimeoutCount = visitTimeoutCount;
1244
1273
  report.visitRejectionCount = visitRejectionCount;
package/tests/axe.js CHANGED
@@ -3,13 +3,26 @@
3
3
  This test implements the axe-core ruleset for accessibility.
4
4
 
5
5
  The rules argument defaults to all rules; otherwise, specify an array of rule names.
6
- Experimental, needs-review, and best-practice rules are ignored.
6
+
7
+ The detailLevel argument specifies how many result categories are to be included in the
8
+ details. 0 = none; 1 = violations; 2 = violations and incomplete; 3 = violations, incomplete,
9
+ and passes; 4 = violations, incomplete, passes, and inapplicable. Regardless of the value of this
10
+ argument, Axe-core is instructed to report all nodes with violation or incomplete results, but only
11
+ 1 node per rule found to be passed or inapplicable. Therefore, from the results of this test it
12
+ is possible to count the rules passed and the inapplicable rules, but not the nodes for which each
13
+ rule is passed or inapplicable. To count those nodes, one would need to revise the 'resultTypes'
14
+ property of the 'axeOptions' object.
15
+
16
+ The report of this test shows rule totals by result category and, within the violation and
17
+ incomplete categories, node totals by severity. It does not show rule or node totals by test
18
+ category (“tag”), such as 'wcag21aaa'. Scoring can consider test categories by getting the value
19
+ of the 'tags' property of each rule.
7
20
  */
8
21
  // IMPORTS
9
- const {injectAxe, getViolations} = require('axe-playwright');
22
+ const {injectAxe, getAxeResults} = require('axe-playwright');
10
23
  // FUNCTIONS
11
24
  // Conducts and reports an Axe test.
12
- exports.reporter = async (page, withItems, rules = []) => {
25
+ exports.reporter = async (page, detailLevel, rules = []) => {
13
26
  // Initialize the report.
14
27
  const data = {};
15
28
  // Inject axe-core into the page.
@@ -22,81 +35,65 @@ exports.reporter = async (page, withItems, rules = []) => {
22
35
  // If the injection succeeded:
23
36
  if (! data.prevented) {
24
37
  // Get the data on the elements violating the specified axe-core rules.
25
- const axeOptions = {};
38
+ const axeOptions = {
39
+ resultTypes: ['violations', 'incomplete']
40
+ };
26
41
  if (rules.length) {
27
42
  axeOptions.runOnly = rules;
28
43
  }
29
- const axeReport = await getViolations(page, null, axeOptions)
44
+ else {
45
+ axeOptions.runOnly = ['experimental', 'best-practice', 'wcag2a', 'wcag2aa', 'wcag2aaa', 'wcag21a', 'wcag21aa', 'wcag21aaa'];
46
+ }
47
+ const axeReport = await getAxeResults(page, null, axeOptions)
30
48
  .catch(error => {
31
49
  console.log(`ERROR: Axe failed (${error.message}'`);
32
50
  return '';
33
51
  });
34
52
  // If the test succeeded:
35
- if (Array.isArray(axeReport)) {
36
- // Initialize a report.
37
- data.warnings = 0;
38
- data.violations = {
39
- minor: 0,
40
- moderate: 0,
41
- serious: 0,
42
- critical: 0
53
+ const {inapplicable, passes, incomplete, violations} = axeReport;
54
+ if (violations) {
55
+ // Initialize the result.
56
+ data.totals = {
57
+ rulesNA: 0,
58
+ rulesPassed: 0,
59
+ rulesWarned: 0,
60
+ rulesViolated: 0,
61
+ warnings: {
62
+ minor: 0,
63
+ moderate: 0,
64
+ serious: 0,
65
+ critical: 0
66
+ },
67
+ violations: {
68
+ minor: 0,
69
+ moderate: 0,
70
+ serious: 0,
71
+ critical: 0
72
+ }
43
73
  };
44
- if (withItems) {
45
- data.items = [];
46
- }
47
- // If there were any violations:
48
- if (axeReport.length) {
49
- // FUNCTION DEFINITIONS START
50
- // Compacts a check violation.
51
- const compactCheck = checkObj => {
52
- return {
53
- check: checkObj.id,
54
- description: checkObj.message,
55
- impact: checkObj.impact
56
- };
57
- };
58
- // Compacts a violating element.
59
- const compactViolator = elObj => {
60
- const out = {
61
- selector: elObj.target[0],
62
- impact: elObj.impact
63
- };
64
- if (elObj.any && elObj.any.length) {
65
- out['must pass any of'] = elObj.any.map(checkObj => compactCheck(checkObj));
66
- }
67
- if (elObj.none && elObj.none.length) {
68
- out['must pass all of'] = elObj.none.map(checkObj => compactCheck(checkObj));
69
- }
70
- return out;
71
- };
72
- // Compacts a violated rule.
73
- const compactRule = rule => {
74
- const out = {
75
- rule: rule.id,
76
- description: rule.description,
77
- impact: rule.impact,
78
- elements: {}
79
- };
80
- if (rule.nodes && rule.nodes.length) {
81
- out.elements = rule.nodes.map(el => compactViolator(el));
82
- }
83
- return out;
84
- };
85
- // FUNCTION DEFINITIONS END
86
- // For each rule violated:
87
- axeReport.forEach(rule => {
88
- // For each element violating the rule:
89
- rule.nodes.forEach(element => {
90
- // Increment the element count of the impact of its violation.
91
- data.violations[element.impact]++;
92
- });
93
- // If details are required:
94
- if (withItems) {
95
- // Add it to the report.
96
- data.items.push(compactRule(rule));
97
- }
74
+ data.details = axeReport;
75
+ // Populate the totals.
76
+ const {totals} = data;
77
+ totals.rulesNA = inapplicable.length;
78
+ totals.rulesPassed = passes.length;
79
+ incomplete.forEach(rule => {
80
+ totals.rulesWarned++;
81
+ rule.nodes.forEach(node => {
82
+ totals.warnings[node.impact]++;
83
+ });
84
+ });
85
+ violations.forEach(rule => {
86
+ totals.rulesViolated++;
87
+ rule.nodes.forEach(node => {
88
+ totals.violations[node.impact]++;
98
89
  });
99
- }
90
+ });
91
+ // Delete irrelevant properties from the report details.
92
+ const irrelevants = ['inapplicable', 'passes', 'incomplete', 'violations']
93
+ .slice(0, 4 - detailLevel);
94
+ irrelevants.forEach(irrelevant => {
95
+ delete axeReport[irrelevant];
96
+ });
100
97
  }
101
98
  // Otherwise, i.e. if the test failed:
102
99
  else {
package/tests/focOp.js CHANGED
@@ -1,5 +1,10 @@
1
1
  /*
2
2
  focOp
3
+
4
+ WARNING: The chromium and firefox browsers in Playwright make errors on this test by
5
+ misclassifying the cursor property values of the computed styles of elements. Launch the
6
+ webkit browser to run this test.
7
+
3
8
  This test reports descrepancies between Tab-focusability and operability. The standard
4
9
  practice is to make focusable elements operable and vice versa. If focusable elements are not
5
10
  operable, users are likely to be surprised that nothing happens when they try to operate such