Commit df1eef5d df1eef5db914643864728c6733d4ad47f0ec7440 by Nicolas Perriault

fixes #699 - getPageContent() throws error when content is not HTML

1 parent 95c131b2
......@@ -915,10 +915,14 @@ Casper.prototype.getPageContent = function getPageContent() {
if (!utils.isString(contentType)) {
return this.page.frameContent;
}
// for some reason webkit/qtwebkit will always enclose body contents within html tags
// for some reason (qt)webkit will always enclose non text/html body contents within an html
// structure like this:
// <html><head></head><body><pre style="(...)">content</pre></body></html>
var sanitizedHtml = this.evaluate(function checkHtml() {
if (__utils__.findOne('head').childNodes.length === 0 &&
__utils__.findOne('body').childNodes.length === 1 &&
var head = __utils__.findOne('head'),
body = __utils__.findOne('body');
if (head && head.childNodes.length === 0 &&
body && body.childNodes.length === 1 &&
__utils__.findOne('body pre[style]')) {
return __utils__.findOne('body pre').textContent.trim();
}
......
var fs = require("fs");
casper.test.begin("Casper.getPageContent() text/html content", 1, function(test) {
casper.start("tests/site/test.html", function() {
test.assertMatch(this.getPageContent(), /<title>CasperJS test target/,
"Casper.getPageContent() retrieves text/html content");
}).run(function() {
test.done();
});
});
casper.test.begin("Casper.getPageContent() non text/html content", 1, function(test) {
casper.start("tests/site/dummy.js", function() {
test.assertEquals(this.getPageContent(), "document.write('foo');",
"Casper.getPageContent() retrieves non text/html content");
}).run(function() {
test.done();
});
});