Commit 5a0a49ff 5a0a49fff6e5b73ba26d4733ce52bb6b363de8c4 by Nicolas Perriault

added jsdoc for phantom.Casper.XUnitExporter

1 parent 6eb73e0b
...@@ -1111,6 +1111,10 @@ ...@@ -1111,6 +1111,10 @@
1111 }; 1111 };
1112 }; 1112 };
1113 1113
1114 /**
1115 * JUnit XML (xUnit) exporter for test results.
1116 *
1117 */
1114 phantom.Casper.XUnitExporter = function() { 1118 phantom.Casper.XUnitExporter = function() {
1115 var node = function(name, attributes) { 1119 var node = function(name, attributes) {
1116 var node = document.createElement(name); 1120 var node = document.createElement(name);
...@@ -1128,6 +1132,9 @@ ...@@ -1128,6 +1132,9 @@
1128 return this.outerHTML; // ouch 1132 return this.outerHTML; // ouch
1129 }; 1133 };
1130 1134
1135 /**
1136 * Adds a successful test result
1137 */
1131 this.addSuccess = function(classname, name) { 1138 this.addSuccess = function(classname, name) {
1132 xml.appendChild(node('testcase', { 1139 xml.appendChild(node('testcase', {
1133 classname: classname, 1140 classname: classname,
...@@ -1135,6 +1142,9 @@ ...@@ -1135,6 +1142,9 @@
1135 })); 1142 }));
1136 }; 1143 };
1137 1144
1145 /**
1146 * Adds a failed test result
1147 */
1138 this.addFailure = function(classname, name, message, type) { 1148 this.addFailure = function(classname, name, message, type) {
1139 var fnode = node('testcase', { 1149 var fnode = node('testcase', {
1140 classname: classname, 1150 classname: classname,
...@@ -1148,6 +1158,9 @@ ...@@ -1148,6 +1158,9 @@
1148 xml.appendChild(fnode); 1158 xml.appendChild(fnode);
1149 }; 1159 };
1150 1160
1161 /**
1162 * Retrieves generated XML object.
1163 */
1151 this.getXML = function() { 1164 this.getXML = function() {
1152 return xml; 1165 return xml;
1153 } 1166 }
...@@ -1238,9 +1251,9 @@ ...@@ -1238,9 +1251,9 @@
1238 /** 1251 /**
1239 * Object recursive merging utility. 1252 * Object recursive merging utility.
1240 * 1253 *
1241 * @param object obj1 the destination object 1254 * @param Object obj1 the destination object
1242 * @param object obj2 the source object 1255 * @param Object obj2 the source object
1243 * @return object 1256 * @return Object
1244 */ 1257 */
1245 function mergeObjects(obj1, obj2) { 1258 function mergeObjects(obj1, obj2) {
1246 for (var p in obj2) { 1259 for (var p in obj2) {
...@@ -1261,9 +1274,9 @@ ...@@ -1261,9 +1274,9 @@
1261 * Replaces a function string contents with placeholders provided by an 1274 * Replaces a function string contents with placeholders provided by an
1262 * Object. 1275 * Object.
1263 * 1276 *
1264 * @param function fn The function 1277 * @param Function fn The function
1265 * @param object replacements Object containing placeholder replacements 1278 * @param Object replacements Object containing placeholder replacements
1266 * @return string A function string representation 1279 * @return String A function string representation
1267 */ 1280 */
1268 function replaceFunctionPlaceholders(fn, replacements) { 1281 function replaceFunctionPlaceholders(fn, replacements) {
1269 if (replacements && typeof replacements === "object") { 1282 if (replacements && typeof replacements === "object") {
......
1 phantom.injectJs('casper.js'); 1 phantom.injectJs('casper.js');
2 2
3 var links = [];
4 var casper = new phantom.Casper();
5
3 function getLinks() { 6 function getLinks() {
4 var links = document.querySelectorAll('h3.r a'); 7 var links = document.querySelectorAll('h3.r a');
5 return Array.prototype.map.call(links, function(e) { 8 return Array.prototype.map.call(links, function(e) {
6 return { 9 return e.getAttribute('href')
7 title: e.innerText,
8 href: e.getAttribute('href')
9 };
10 }); 10 });
11 } 11 }
12 12
13 var links = []; 13 casper.start('http://google.fr/', function(self) {
14 var casper = new phantom.Casper({ 14 // search for 'casperjs' from google form
15 faultTolerant: false, 15 self.fill('form[name=f]', { q: 'casperjs' }, true);
16 logLevel: "debug", // we only want "info" or higher level log messages 16 });
17 loadImages: false, // do not download images to save bandwidth 17
18 loadPlugins: false, // do not load plugins to save kitten 18 casper.then(function(self) {
19 verbose: true // write log messages to the console 19 // aggregate results for the 'casperjs' search
20 }) 20 links = self.evaluate(getLinks);
21 .start('http://google.fr/') 21 // now search for 'phantomjs' by fillin the form again
22 .then(function(self) { 22 self.fill('form[name=f]', { q: 'phantomjs' }, true);
23 // search for 'casperjs' from google form 23 });
24 self.fill('form[name=f]', { 24
25 q: 'casperjs' 25 casper.then(function(self) {
26 }, true); 26 // aggregate results for the 'phantomjs' search
27 }) 27 links = links.concat(self.evaluate(getLinks));
28 .then(function(self) { 28 });
29 // aggregate results for the 'casperjs' search 29
30 links = self.evaluate(getLinks); 30 casper.run(function(self) {
31 // now search for 'phantomjs' by fillin the form again 31 // echo results in some pretty fashion
32 self.fill('form[name=f]', { 32 self.echo(links.length + ' links found:');
33 q: 'phantomjs' 33 self.echo(' - ' + links.join('\n - ')).exit();
34 }, true); 34 });
35 })
36 .then(function(self) {
37 // aggregate results for the 'phantomjs' search
38 links = links.concat(self.evaluate(getLinks));
39 })
40 .run(function(self) {
41 // echo results in some pretty fashion
42 self.echo(links.map(function(i) {
43 return i.title + ' (' + i.href + ')';
44 }).join('\n')).exit();
45 })
46 ;
......