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() { ...@@ -706,6 +706,20 @@ Casper.prototype.getCurrentUrl = function getCurrentUrl() {
706 }; 706 };
707 707
708 /** 708 /**
709 * Retrieves the value of an attribute on the first element matching the provided CSS3 selector.
710 *
711 * @param String selector A CSS3 selector
712 * @param String attribute The attribute to lookup
713 * @return String The requested DOM element
714 */
715 Casper.prototype.getElementAttribute = Casper.prototype.getElementAttr = function getElementAttr(selector, attribute) {
716 "use strict";
717 return this.evaluate(function _evaluate(selector, attribute) {
718 return document.querySelector(selector).getAttribute(attribute);
719 }, { selector: selector, attribute: attribute });
720 };
721
722 /**
709 * Retrieves boundaries for a DOM element matching the provided CSS3 selector. 723 * Retrieves boundaries for a DOM element matching the provided CSS3 selector.
710 * 724 *
711 * @param String selector A CSS3 selector 725 * @param String selector A CSS3 selector
......
...@@ -68,6 +68,7 @@ var Tester = function Tester(casper, options) { ...@@ -68,6 +68,7 @@ var Tester = function Tester(casper, options) {
68 this.testResults = { 68 this.testResults = {
69 passed: 0, 69 passed: 0,
70 failed: 0, 70 failed: 0,
71 passes: [],
71 failures: [] 72 failures: []
72 }; 73 };
73 74
...@@ -87,6 +88,7 @@ var Tester = function Tester(casper, options) { ...@@ -87,6 +88,7 @@ var Tester = function Tester(casper, options) {
87 }); 88 });
88 89
89 this.on('success', function onSuccess(success) { 90 this.on('success', function onSuccess(success) {
91 this.testResults.passes.push(success);
90 this.exporter.addSuccess(fs.absolute(success.file), success.message); 92 this.exporter.addSuccess(fs.absolute(success.file), success.message);
91 }); 93 });
92 94
...@@ -563,6 +565,34 @@ var Tester = function Tester(casper, options) { ...@@ -563,6 +565,34 @@ var Tester = function Tester(casper, options) {
563 }; 565 };
564 566
565 /** 567 /**
568 * Retrieves current failure data and all failed cases.
569 *
570 * @return Object casedata An object containg information about cases
571 * @return Number casedata.length The number of failed cases
572 * @return Array casedata.cases An array of all the failed case objects
573 */
574 this.getFailures = function getFailures() {
575 return {
576 length: this.testResults.failed,
577 cases: this.testResults.failures
578 };
579 };
580
581 /**
582 * Retrieves current passed data and all passed cases.
583 *
584 * @return Object casedata An object containg information about cases
585 * @return Number casedata.length The number of passed cases
586 * @return Array casedata.cases An array of all the passed case objects
587 */
588 this.getPasses = function getPasses() {
589 return {
590 length: this.testResults.passed,
591 cases: this.testResults.passes
592 };
593 };
594
595 /**
566 * Writes an info-style formatted message to stdout. 596 * Writes an info-style formatted message to stdout.
567 * 597 *
568 * @param String message 598 * @param String message
......
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <div class="tester testo testme" data-stuff="beautiful string"></div>
5 </body>
6 </html>
...\ No newline at end of file ...\ No newline at end of file
1 casper.start('tests/site/elementattribute.html', function() {
2 this.test.comment('Casper.getElementAttribute()');
3 this.test.assertEquals(this.getElementAttribute('.testo','data-stuff'), 'beautiful string', 'Casper.getElementAttribute() works as intended');
4 });
5
6 casper.run(function() {
7 this.test.done();
8 });
...@@ -106,6 +106,16 @@ casper.then(function() { ...@@ -106,6 +106,16 @@ casper.then(function() {
106 t.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected"); 106 t.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected");
107 }); 107 });
108 108
109 casper.then(function() {
110 t.comment('Tester.getFailures()');
111 t.assertEquals(typeof t.getFailures().length, "number", "Tester.getFailures() works as expected");
112
113 var passCount = t.getPasses().length;
114 t.comment('Tester.getPasses()');
115 t.assertEquals(1, 1, "Rogue assertEquals pass case");
116 t.assertEquals(t.getPasses().length, passCount + 1, "Tester.getPasses() works as expected");
117 });
118
109 casper.run(function() { 119 casper.run(function() {
110 t.done(); 120 t.done();
111 }); 121 });
......