Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(a11yPlugin): add success/fail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Feb 24, 2015
1 parent 097cbbf commit 486a2e0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
44 changes: 29 additions & 15 deletions plugins/accessibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,48 @@ function teardown(config) {
return browser.executeScript_(data, 'a11y developer tool rules').then(function(results) {

var audit = results.map(function(result) {

var DOMElements = result.elements;
if (DOMElements !== undefined) {

DOMElements.forEach(function(elem) {
// get elements from WebDriver
// get elements from WebDriver, add to promises array
elementPromises.push(
elem.getOuterHtml().then(function(text) {
return '\n\t\t' + text;
return {
code: result.rule.code,
list: text
};
})
);
});
result.elementCount = DOMElements.length;
}

if (result.result === 'FAIL') {
result.passed = false;
testOut.failedCount++;
}
else {
result.passed = true;
}

return result;
});

// Wait for element names to be fetched
return q.all(elementPromises).then(function(message) {
audit.forEach(function(result) {
result.message = message;
return q.all(elementPromises).then(function(elementFailures) {

audit.forEach(function(result, index) {
if (result.result === 'FAIL') {
result.passed = false;
testOut.failedCount++;

var label = result.elementCount === 1 ? ' element ' : ' elements ';
result.message = '\n\t\t' + result.elementCount + label + 'failed:';

// match elements returned via promises
// by their failure codes
elementFailures.forEach(function(element, index) {
if (element.code === result.rule.code) {
result.message += '\n\t\t' + elementFailures[index].list;
}
});
}
else {
result.passed = true;
result.message = null;
}
result.message += '\n\n\t\t' + result.rule.url;

testOut.specResults.push({
Expand Down
5 changes: 2 additions & 3 deletions plugins/accessibility/spec/fail_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe('check if accessibility plugin works on bad apps', function() {
it('should have accessibility problems on bad apps', function() {
browser.get('accessibility/noContent.html');
browser.get('accessibility/unused.html');
it('should have accessibility problems on markup', function() {
browser.get('accessibility/badMarkup.html');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
Last name:<input ng-model="lastName" type="text"/>
<br>
Hello {{firstName}} {{lastName}}
<img src="http://example.com/img.jpg">
</body>
</html>
9 changes: 6 additions & 3 deletions testapp/accessibility/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
angular.module('xApp', []);
</script>
</head>
<body class="a11y">
First name:<input ng-model="firstName" type="text"/>
<body>
<label for="firstName">First name:</label>
<input ng-model="firstName" type="text" id="firstName" />
<br>
Last name:<input ng-model="lastName" type="text"/>
<label for="lastName">Last name:</label>
<input ng-model="lastName" type="text" id="lastName" />
<br>
Hello {{firstName}} {{lastName}}
<img src="http://example.com/img.jpg" alt="{{firstName}} {{lastName}}">
</body>
</html>
15 changes: 0 additions & 15 deletions testapp/accessibility/noContent.html

This file was deleted.

0 comments on commit 486a2e0

Please sign in to comment.