testaro 4.6.1 → 4.7.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
@@ -166,8 +166,9 @@ exports.commands = {
166
166
  focInd: [
167
167
  'Perform a focInd test',
168
168
  {
169
- withItems: [true, 'boolean'],
170
- revealAll: [true, 'boolean', '', 'whether to make all elements visible first']
169
+ revealAll: [true, 'boolean', '', 'whether to make all elements visible first'],
170
+ allowedDelay: [true, 'number', '', 'milliseconds to wait for an outline'],
171
+ withItems: [true, 'boolean']
171
172
  }
172
173
  ],
173
174
  focOp: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "4.6.1",
3
+ "version": "4.7.0",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tests/focInd.js CHANGED
@@ -1,21 +1,24 @@
1
1
  /*
2
2
  focInd
3
3
  This test reports focusable elements without focus indicators, with non-outline focus
4
- indicators, and with outline focus indicators.
5
-
6
- It as based on the assumption that outlines are the standard and thus most familiar
7
- focus indicator. Other focus indicators are assumed better than none, but more likely
8
- to be misunderstood. For example, underlines may be mistaken for selection indicators.
4
+ indicators, and with outline focus indicators. An outline is recognized if it has non-zero
5
+ line thickness and non-transparent color. The test is based on the assumption that outlines are
6
+ the standard and thus most familiar focus indicator. Other focus indicators are assumed better
7
+ than none, but more likely to be misunderstood. For example, underlines may be mistaken for
8
+ selection indicators. Some pages delay the appearance of focus indicators. This test waits for
9
+ focus indicators to appear if specified and, if there is a delay, reports on its magnitude.
9
10
 
10
11
  Bug: This test fails to recognize outlines when run with firefox.
11
12
  */
12
- exports.reporter = async (page, withItems, revealAll) => {
13
+ exports.reporter = async (page, revealAll, allowedDelay, withItems) => {
13
14
  // If required, make all elements visible.
14
15
  if (revealAll) {
15
16
  await require('../procs/allVis').allVis(page);
16
17
  }
17
18
  // Get data on the focusable visible elements with and without indicators.
18
- const data = await page.$$eval('body *:visible', (elements, withItems) => {
19
+ const data = await page.$$eval('body *:visible', async (elements, args) => {
20
+ const allowedDelay = args[0];
21
+ const withItems = args[1];
19
22
  // Initialize the data.
20
23
  const data = {
21
24
  totals: {
@@ -31,6 +34,7 @@ exports.reporter = async (page, withItems, revealAll) => {
31
34
  },
32
35
  outlinePresent: {
33
36
  total: 0,
37
+ meanDelay: 0,
34
38
  tagNames: {}
35
39
  }
36
40
  }
@@ -43,9 +47,13 @@ exports.reporter = async (page, withItems, revealAll) => {
43
47
  outlinePresent: []
44
48
  };
45
49
  }
46
- const addElementFacts = (element, status) => {
50
+ // Adds facts about an element to the result.
51
+ const addElementFacts = (element, status, delay = null) => {
47
52
  const type = data.totals.types[status];
48
53
  type.total++;
54
+ if (status === 'outlinePresent') {
55
+ type.meanDelay = Math.round(((type.total - 1) * type.meanDelay + delay) / type.total);
56
+ }
49
57
  const tagName = element.tagName;
50
58
  if (type.tagNames[tagName]) {
51
59
  type.tagNames[tagName]++;
@@ -54,46 +62,91 @@ exports.reporter = async (page, withItems, revealAll) => {
54
62
  type.tagNames[tagName] = 1;
55
63
  }
56
64
  if (withItems) {
57
- data.items[status].push({
65
+ const elementData = {
58
66
  tagName,
59
67
  text: element.textContent.trim().replace(/\s{2,}/g, ' ').slice(0, 100)
60
- });
68
+ };
69
+ if (status === 'outlinePresent') {
70
+ elementData.delay = delay;
71
+ }
72
+ data.items[status].push(elementData);
61
73
  }
62
74
  };
63
- elements.forEach(element => {
75
+ // For each visible element descendant of the body:
76
+ for(const element of elements) {
77
+ // If it is Tab-focusable:
64
78
  if (element.tabIndex === 0) {
79
+ // Increment the total of focusable elements.
65
80
  data.totals.total++;
66
- const styleBlurred = Object.assign({}, window.getComputedStyle(element));
81
+ // Get a live style declaration of its properties.
82
+ const styleDec = window.getComputedStyle(element);
83
+ // Freeze a copy to preserve the style properties when not focused.
84
+ const styleBlurred = Object.assign({}, styleDec);
85
+ // Focus it, potentially changing the properties in its style declaration.
67
86
  element.focus({preventScroll: true});
68
- const styleFocused = window.getComputedStyle(element);
69
- const hasOutline
70
- = styleBlurred.outlineWidth === '0px'
71
- && styleFocused.outlineWidth !== '0px';
72
- if (hasOutline) {
73
- addElementFacts(element, 'outlinePresent');
87
+ let hasOutline = false;
88
+ // If it has no outline when not focused:
89
+ if (styleBlurred.outlineWidth === '0px') {
90
+ // If an outline appeared immediately on focus:
91
+ if (styleDec.outlineWidth !== '0px' && styleDec.outlineColor !== 'rgba(0, 0, 0, 0)') {
92
+ // Add facts about the element to the result.
93
+ addElementFacts(element, 'outlinePresent', 0);
94
+ hasOutline = true;
95
+ }
96
+ // Otherwise, if a wait for an outline is allowed:
97
+ else if (allowedDelay) {
98
+ // Determine how long an outline takes to appear or whether it times out.
99
+ const outlineDelay = new Promise(resolve => {
100
+ const focusTime = Date.now();
101
+ const deadline = focusTime + allowedDelay;
102
+ const interval = setInterval(() => {
103
+ if (
104
+ styleDec.outlineWidth !== '0px' && styleDec.outlineColor !== 'rgba(0, 0, 0, 0)'
105
+ ) {
106
+ resolve(Date.now() - focusTime);
107
+ clearInterval(interval);
108
+ }
109
+ else if (Date.now() > deadline) {
110
+ resolve(null);
111
+ clearInterval(interval);
112
+ }
113
+ }, 100);
114
+ });
115
+ // If it appeared before the wait limit:
116
+ const delay = await outlineDelay;
117
+ if (delay) {
118
+ // Add facts about the element to the result.
119
+ addElementFacts(element, 'outlinePresent', delay);
120
+ hasOutline = true;
121
+ }
122
+ }
74
123
  }
75
- else {
76
- const diff = prop => styleFocused[prop] !== styleBlurred[prop];
124
+ // If no outline was allowed:
125
+ if (! hasOutline) {
126
+ // Returns whether a style property differs between focused and not focused.
127
+ const diff = prop => styleDec[prop] !== styleBlurred[prop];
128
+ // Determine whether the element has another allowed focus indicator.
77
129
  const hasIndicator
78
- = diff('borderStyle')
79
- && styleBlurred.borderWidth !== '0px'
80
- && styleFocused.borderWidth !== '0px'
81
- || (styleFocused.borderStyle !== 'none' && diff('borderWidth'))
82
- || diff('outlineStyle')
83
- && styleBlurred.outlineWidth !== '0px'
84
- && styleFocused.outlineWidth !== '0px'
85
- || (styleFocused.outlineStyle !== 'none' && diff('outlineWidth'))
86
- || diff('fontSize')
87
- || diff('fontStyle')
88
- || diff('textDecorationLine')
89
- || diff('textDecorationStyle')
90
- || diff('textDecorationThickness');
130
+ = diff('borderStyle')
131
+ && styleBlurred.borderWidth !== '0px'
132
+ && styleDec.borderWidth !== '0px'
133
+ || (styleDec.borderStyle !== 'none' && diff('borderWidth'))
134
+ || diff('outlineStyle')
135
+ && styleBlurred.outlineWidth !== '0px'
136
+ && styleDec.outlineWidth !== '0px'
137
+ || (styleDec.outlineStyle !== 'none' && diff('outlineWidth'))
138
+ || diff('fontSize')
139
+ || diff('fontStyle')
140
+ || diff('textDecorationLine')
141
+ || diff('textDecorationStyle')
142
+ || diff('textDecorationThickness');
143
+ // Add the determination to the result.
91
144
  const status = hasIndicator ? 'nonOutlinePresent' : 'indicatorMissing';
92
145
  addElementFacts(element, status);
93
146
  }
94
147
  }
95
- });
148
+ };
96
149
  return data;
97
- }, withItems);
150
+ }, [allowedDelay, withItems]);
98
151
  return {result: data};
99
152
  };