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
3347f9e9
...
3347f9e9d857098ad544fdd90aaae966901ceb67
authored
2012-05-07 09:20:36 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #107: client utils were possibly not yet injected sometimes
1 parent
a00ae19f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
modules/casper.js
tests/suites/casper/encode.js
modules/casper.js
View file @
3347f9e
...
...
@@ -146,6 +146,7 @@ Casper.prototype.back = function back() {
* @return string Base64 encoded result
*/
Casper
.
prototype
.
base64encode
=
function
base64encode
(
url
,
method
,
data
)
{
this
.
injectClientUtils
();
return
this
.
evaluate
(
function
_evaluate
(
url
,
method
,
data
)
{
return
__utils__
.
getBase64
(
url
,
method
,
data
);
},
{
url
:
url
,
method
:
method
,
data
:
data
});
...
...
@@ -608,6 +609,25 @@ Casper.prototype.getTitle = function getTitle() {
};
/**
* Injects Client-side utilities in current page context.
*
*/
Casper
.
prototype
.
injectClientUtils
=
function
injectClientUtils
()
{
var
clientUtilsInjected
=
this
.
evaluate
(
function
()
{
return
typeof
__utils__
===
"object"
;
});
if
(
true
===
clientUtilsInjected
)
{
return
;
}
var
clientUtilsPath
=
require
(
'fs'
).
pathJoin
(
phantom
.
casperPath
,
'modules'
,
'clientutils.js'
);
if
(
true
===
this
.
page
.
injectJs
(
clientUtilsPath
))
{
this
.
log
(
"Successfully injected Casper client-side utilities"
,
"debug"
);
}
else
{
this
.
log
(
"Failed to instantiate Casper client-side utilities!"
,
"warning"
);
}
};
/**
* Logs a message.
*
* @param String message The message to log
...
...
@@ -1297,12 +1317,7 @@ function createPage(casper) {
}
}
// Client-side utils injection
var
clientUtilsPath
=
fs
.
pathJoin
(
phantom
.
casperPath
,
'modules'
,
'clientutils.js'
);
if
(
true
===
page
.
injectJs
(
clientUtilsPath
))
{
casper
.
log
(
"Successfully injected Casper client-side utilities"
,
"debug"
);
}
else
{
casper
.
log
(
"Failed to instantiate Casper client-side utilities!"
,
"warning"
);
}
casper
.
injectClientUtils
();
// history
casper
.
history
.
push
(
casper
.
getCurrentUrl
());
casper
.
emit
(
'load.finished'
,
status
);
...
...
tests/suites/casper/encode.js
View file @
3347f9e
...
...
@@ -8,10 +8,10 @@ casper.start('tests/site/index.html', function() {
this
.
test
.
assertEquals
(
image
.
length
,
6160
,
'Casper.base64encode() can retrieve base64 contents'
);
this
.
test
.
comment
(
'Casper.download()'
);
this
.
download
(
imageUrl
,
'logo.png'
);
this
.
test
.
assert
(
fs
.
exists
(
'logo.png'
),
'Casper.download() downloads a file'
);
if
(
fs
.
exists
(
'logo.png'
))
{
fs
.
remove
(
'logo.png'
);
this
.
download
(
imageUrl
,
'
__test_
logo.png'
);
this
.
test
.
assert
(
fs
.
exists
(
'
__test_
logo.png'
),
'Casper.download() downloads a file'
);
if
(
fs
.
exists
(
'
__test_
logo.png'
))
{
fs
.
remove
(
'
__test_
logo.png'
);
}
});
...
...
Please
register
or
sign in
to post a comment