Commit 5a0a49ff 5a0a49fff6e5b73ba26d4733ce52bb6b363de8c4 by Nicolas Perriault

added jsdoc for phantom.Casper.XUnitExporter

1 parent 6eb73e0b
......@@ -1111,6 +1111,10 @@
};
};
/**
* JUnit XML (xUnit) exporter for test results.
*
*/
phantom.Casper.XUnitExporter = function() {
var node = function(name, attributes) {
var node = document.createElement(name);
......@@ -1128,6 +1132,9 @@
return this.outerHTML; // ouch
};
/**
* Adds a successful test result
*/
this.addSuccess = function(classname, name) {
xml.appendChild(node('testcase', {
classname: classname,
......@@ -1135,6 +1142,9 @@
}));
};
/**
* Adds a failed test result
*/
this.addFailure = function(classname, name, message, type) {
var fnode = node('testcase', {
classname: classname,
......@@ -1148,6 +1158,9 @@
xml.appendChild(fnode);
};
/**
* Retrieves generated XML object.
*/
this.getXML = function() {
return xml;
}
......@@ -1238,9 +1251,9 @@
/**
* Object recursive merging utility.
*
* @param object obj1 the destination object
* @param object obj2 the source object
* @return object
* @param Object obj1 the destination object
* @param Object obj2 the source object
* @return Object
*/
function mergeObjects(obj1, obj2) {
for (var p in obj2) {
......@@ -1261,9 +1274,9 @@
* Replaces a function string contents with placeholders provided by an
* Object.
*
* @param function fn The function
* @param object replacements Object containing placeholder replacements
* @return string A function string representation
* @param Function fn The function
* @param Object replacements Object containing placeholder replacements
* @return String A function string representation
*/
function replaceFunctionPlaceholders(fn, replacements) {
if (replacements && typeof replacements === "object") {
......
phantom.injectJs('casper.js');
var links = [];
var casper = new phantom.Casper();
function getLinks() {
var links = document.querySelectorAll('h3.r a');
return Array.prototype.map.call(links, function(e) {
return {
title: e.innerText,
href: e.getAttribute('href')
};
return e.getAttribute('href')
});
}
var links = [];
var casper = new phantom.Casper({
faultTolerant: false,
logLevel: "debug", // we only want "info" or higher level log messages
loadImages: false, // do not download images to save bandwidth
loadPlugins: false, // do not load plugins to save kitten
verbose: true // write log messages to the console
})
.start('http://google.fr/')
.then(function(self) {
// search for 'casperjs' from google form
self.fill('form[name=f]', {
q: 'casperjs'
}, true);
})
.then(function(self) {
// aggregate results for the 'casperjs' search
links = self.evaluate(getLinks);
// now search for 'phantomjs' by fillin the form again
self.fill('form[name=f]', {
q: 'phantomjs'
}, true);
})
.then(function(self) {
// aggregate results for the 'phantomjs' search
links = links.concat(self.evaluate(getLinks));
})
.run(function(self) {
// echo results in some pretty fashion
self.echo(links.map(function(i) {
return i.title + ' (' + i.href + ')';
}).join('\n')).exit();
})
;
casper.start('http://google.fr/', function(self) {
// search for 'casperjs' from google form
self.fill('form[name=f]', { q: 'casperjs' }, true);
});
casper.then(function(self) {
// aggregate results for the 'casperjs' search
links = self.evaluate(getLinks);
// now search for 'phantomjs' by fillin the form again
self.fill('form[name=f]', { q: 'phantomjs' }, true);
});
casper.then(function(self) {
// aggregate results for the 'phantomjs' search
links = links.concat(self.evaluate(getLinks));
});
casper.run(function(self) {
// echo results in some pretty fashion
self.echo(links.length + ' links found:');
self.echo(' - ' + links.join('\n - ')).exit();
});
......