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
df1009e1
...
df1009e1b0202566614269040784e3a528d95651
authored
2012-05-27 14:32:06 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' into tester-refactor
2 parents
236aba1c
3aa64e34
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
14 deletions
CHANGELOG.md
docs
modules/casper.js
modules/clientutils.js
samples/googlematch.coffee
samples/googlematch.js
CHANGELOG.md
View file @
df1009e
...
...
@@ -6,6 +6,8 @@ XXXX-XX-XX, v0.6.9
-
fixed
[
#114
](
https://github.com/n1k0/casperjs/issues/114
)
- ensured client-side utils are injected before any
`evaluate()`
call
-
fixed
[
#117
](
https://github.com/n1k0/casperjs/issues/117
)
-
`fill()`
coulnd't
`submit()`
a form with a submit input named
*submit*
-
merged
[
#122
](
https://github.com/n1k0/casperjs/pull/122
)
- allow downloads to be triggered by more than just
`GET`
requests
-
fixed loaded resources array is now reset adequately
[
reference discussion
](
https://groups.google.com/forum/?hl=fr?fromgroups#!topic/casperjs/TCkNzrj1IoA
)
2012-05-20, v0.6.8
------------------
...
...
docs
@
b9192a22
Subproject commit
c5b5de3e85582ebfe2d2051cd8dbfc5cf67c885a
Subproject commit
b9192a22522dcd8aac843ba769caf384ac00277e
...
...
modules/casper.js
View file @
df1009e
...
...
@@ -350,10 +350,10 @@ Casper.prototype.die = function die(message, status) {
* @param String targetPath The destination file path
* @return Casper
*/
Casper
.
prototype
.
download
=
function
download
(
url
,
targetPath
)
{
Casper
.
prototype
.
download
=
function
download
(
url
,
targetPath
,
method
,
data
)
{
var
cu
=
require
(
'clientutils'
).
create
();
try
{
fs
.
write
(
targetPath
,
cu
.
decode
(
this
.
base64encode
(
url
)),
'w'
);
fs
.
write
(
targetPath
,
cu
.
decode
(
this
.
base64encode
(
url
,
method
,
data
)),
'w'
);
this
.
emit
(
'downloaded.file'
,
targetPath
);
this
.
log
(
f
(
"Downloaded and saved resource in %s"
,
targetPath
));
}
catch
(
e
)
{
...
...
@@ -746,6 +746,7 @@ Casper.prototype.open = function open(location, settings) {
operation
:
settings
.
method
,
data
:
settings
.
data
},
this
.
page
.
settings
);
this
.
resources
=
[];
return
this
;
};
...
...
@@ -775,17 +776,18 @@ Casper.prototype.resourceExists = function resourceExists(test) {
var
testFn
;
switch
(
utils
.
betterTypeOf
(
test
))
{
case
"string"
:
testFn
=
function
_test
(
res
)
{
testFn
=
function
_test
ResourceExists_String
(
res
)
{
return
res
.
url
.
search
(
test
)
!==
-
1
;
};
break
;
case
"regexp"
:
testFn
=
function
_test
(
res
)
{
testFn
=
function
_test
ResourceExists_Regexp
(
res
)
{
return
test
.
test
(
res
.
url
);
};
break
;
case
"function"
:
testFn
=
test
;
testFn
.
name
=
"_testResourceExists_Function"
;
break
;
default
:
throw
new
CasperError
(
"Invalid type"
);
...
...
@@ -1299,7 +1301,6 @@ function createPage(casper) {
};
page
.
onLoadStarted
=
function
onLoadStarted
()
{
casper
.
loadInProgress
=
true
;
casper
.
resources
=
[];
casper
.
emit
(
'load.started'
);
};
page
.
onLoadFinished
=
function
onLoadFinished
(
status
)
{
...
...
modules/clientutils.js
View file @
df1009e
...
...
@@ -546,8 +546,14 @@
*/
this
.
visible
=
function
visible
(
selector
)
{
try
{
var
el
=
this
.
findOne
(
selector
);
return
el
&&
el
.
style
.
visibility
!==
'hidden'
&&
el
.
offsetHeight
>
0
&&
el
.
offsetWidth
>
0
;
var
comp
,
el
=
this
.
findOne
(
selector
);
if
(
el
)
{
comp
=
window
.
getComputedStyle
(
el
,
null
);
return
comp
.
visibility
!==
'hidden'
&&
comp
.
display
!==
'none'
&&
el
.
offsetHeight
>
0
&&
el
.
offsetWidth
>
0
;
}
return
false
;
}
catch
(
e
)
{
return
false
;
}
...
...
samples/googlematch.coffee
View file @
df1009e
...
...
@@ -15,7 +15,7 @@ casper = require('casper').create verbose: true
casper
.
fetchScore
=
->
@
evaluate
->
result
=
document
.
querySelector
(
'#resultStats'
).
innerText
~~
(
/Environ ([0-9\s]{1,}).*/
.
exec
(
result
)[
1
].
replace
(
/\s/g
,
''
)
)
parseInt
/Environ ([0-9\s]{1,}).*/
.
exec
(
result
)[
1
].
replace
(
/\s/g
,
''
)
terms
=
casper
.
cli
.
args
# terms are passed through command-line arguments
...
...
@@ -38,7 +38,7 @@ casper.each terms, (self, term) ->
self
.
echo
"
#{
term
}
:
#{
score
}
"
casper
.
run
->
scores
.
sort
->
(
a
,
b
)
->
b
.
score
-
a
.
score
;
winner
=
scores
[
0
]
winner
=
x
for
x
in
scores
when
x
.
score
>
winner
.
score
@
echo
"Winner is
#{
winner
.
term
}
with
#{
winner
.
score
}
results"
@
exit
()
...
...
samples/googlematch.js
View file @
df1009e
...
...
@@ -16,7 +16,7 @@ var casper = new require('casper').create({
casper
.
fetchScore
=
function
()
{
return
this
.
evaluate
(
function
()
{
var
result
=
document
.
querySelector
(
'#resultStats'
).
innerText
;
return
~~
(
/Environ
([
0-9
\s]{1,})
.*/
.
exec
(
result
)[
1
].
replace
(
/
\s
/g
,
''
));
return
parseInt
(
/Environ
([
0-9
\s]{1,})
.*/
.
exec
(
result
)[
1
].
replace
(
/
\s
/g
,
''
));
});
};
...
...
@@ -45,10 +45,10 @@ casper.each(terms, function(self, term, i) {
});
casper
.
run
(
function
(
self
)
{
scores
.
sort
(
function
(
a
,
b
)
{
return
b
.
score
-
a
.
score
;
});
var
winner
=
scores
[
0
];
for
(
var
i
=
0
,
len
=
scores
.
length
;
i
<
len
;
i
++
)
if
(
scores
[
i
].
score
>
winner
.
score
)
winner
=
scores
[
i
];
self
.
echo
(
'winner is "'
+
winner
.
term
+
'" with '
+
winner
.
score
+
' results'
);
self
.
exit
();
});
...
...
Please
register
or
sign in
to post a comment