Commit 78f126a9 78f126a98b273403f7861df6e90f9b211d8a12d4 by Nicolas Perriault

Merged PR #161

Feature: getElementAttribute, Tester.getFailures, Tester.getPasses
2 parents 62f65d75 a4caf0d5
......@@ -706,6 +706,20 @@ Casper.prototype.getCurrentUrl = function getCurrentUrl() {
};
/**
* Retrieves the value of an attribute on the first element matching the provided CSS3 selector.
*
* @param String selector A CSS3 selector
* @param String attribute The attribute to lookup
* @return String The requested DOM element
*/
Casper.prototype.getElementAttribute = Casper.prototype.getElementAttr = function getElementAttr(selector, attribute) {
"use strict";
return this.evaluate(function _evaluate(selector, attribute) {
return document.querySelector(selector).getAttribute(attribute);
}, { selector: selector, attribute: attribute });
};
/**
* Retrieves boundaries for a DOM element matching the provided CSS3 selector.
*
* @param String selector A CSS3 selector
......
......@@ -68,6 +68,7 @@ var Tester = function Tester(casper, options) {
this.testResults = {
passed: 0,
failed: 0,
passes: [],
failures: []
};
......@@ -87,6 +88,7 @@ var Tester = function Tester(casper, options) {
});
this.on('success', function onSuccess(success) {
this.testResults.passes.push(success);
this.exporter.addSuccess(fs.absolute(success.file), success.message);
});
......@@ -563,6 +565,34 @@ var Tester = function Tester(casper, options) {
};
/**
* Retrieves current failure data and all failed cases.
*
* @return Object casedata An object containg information about cases
* @return Number casedata.length The number of failed cases
* @return Array casedata.cases An array of all the failed case objects
*/
this.getFailures = function getFailures() {
return {
length: this.testResults.failed,
cases: this.testResults.failures
};
};
/**
* Retrieves current passed data and all passed cases.
*
* @return Object casedata An object containg information about cases
* @return Number casedata.length The number of passed cases
* @return Array casedata.cases An array of all the passed case objects
*/
this.getPasses = function getPasses() {
return {
length: this.testResults.passed,
cases: this.testResults.passes
};
};
/**
* Writes an info-style formatted message to stdout.
*
* @param String message
......
<!DOCTYPE html>
<html>
<body>
<div class="tester testo testme" data-stuff="beautiful string"></div>
</body>
</html>
\ No newline at end of file
casper.start('tests/site/elementattribute.html', function() {
this.test.comment('Casper.getElementAttribute()');
this.test.assertEquals(this.getElementAttribute('.testo','data-stuff'), 'beautiful string', 'Casper.getElementAttribute() works as intended');
});
casper.run(function() {
this.test.done();
});
......@@ -106,6 +106,16 @@ casper.then(function() {
t.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected");
});
casper.then(function() {
t.comment('Tester.getFailures()');
t.assertEquals(typeof t.getFailures().length, "number", "Tester.getFailures() works as expected");
var passCount = t.getPasses().length;
t.comment('Tester.getPasses()');
t.assertEquals(1, 1, "Rogue assertEquals pass case");
t.assertEquals(t.getPasses().length, passCount + 1, "Tester.getPasses() works as expected");
});
casper.run(function() {
t.done();
});
......