Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
df1eef5d
...
df1eef5db914643864728c6733d4ad47f0ec7440
authored
2013-11-12 09:29:40 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #699 - getPageContent() throws error when content is not HTML
1 parent
95c131b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
modules/casper.js
tests/suites/casper/content.js
modules/casper.js
View file @
df1eef5
...
...
@@ -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
();
}
...
...
tests/suites/casper/content.js
0 → 100644
View file @
df1eef5
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
();
});
});
Please
register
or
sign in
to post a comment