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
2af64a19
...
2af64a195d4d60bdf0f2c580a8b81d6e6cd339d5
authored
2012-05-21 19:38:33 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' into issue-114
2 parents
fa3ed042
fd9956c5
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
53 additions
and
32 deletions
docs
modules/casper.js
modules/clientutils.js
samples/cliplay.coffee
samples/cliplay.js
samples/customlogging.coffee
samples/googlematch.coffee
samples/googlematch.js
samples/googlepagination.coffee
samples/googlepagination.js
samples/metaextract.coffee
samples/metaextract.js
samples/screenshot.coffee
samples/screenshot.js
samples/timeout.coffee
samples/timeout.js
docs
@
980f9a9c
Subproject commit
100ffeb02edee0d765efd29ef897c25343e24b2d
Subproject commit
980f9a9c31054badf459e11e700fb959df24b3a7
...
...
modules/casper.js
View file @
2af64a1
...
...
@@ -375,11 +375,9 @@ Casper.prototype.each = function each(array, fn) {
this
.
log
(
"each() only works with arrays"
,
"error"
);
return
this
;
}
(
function
_each
(
self
)
{
array
.
forEach
(
function
_forEach
(
item
,
i
)
{
fn
.
call
(
self
,
self
,
item
,
i
);
array
.
forEach
.
call
(
this
,
function
_forEach
(
item
,
i
)
{
fn
.
call
(
this
,
this
,
item
,
i
);
});
})(
this
);
return
this
;
};
...
...
@@ -924,8 +922,8 @@ Casper.prototype.start = function start(location, then) {
},
this
.
options
.
timeout
,
this
);
}
if
(
utils
.
isString
(
location
)
&&
location
.
length
>
0
)
{
return
this
.
thenOpen
(
location
,
utils
.
isFunction
(
then
)
?
then
:
this
.
createStep
(
function
_step
(
self
)
{
self
.
log
(
"start page is loaded"
,
"debug"
);
return
this
.
thenOpen
(
location
,
utils
.
isFunction
(
then
)
?
then
:
this
.
createStep
(
function
_step
()
{
this
.
log
(
"start page is loaded"
,
"debug"
);
}));
}
return
this
;
...
...
modules/clientutils.js
View file @
2af64a1
...
...
@@ -29,13 +29,13 @@
*/
(
function
(
exports
)
{
exports
.
create
=
function
create
()
{
return
new
ClientUtils
();
return
new
this
.
ClientUtils
();
};
/**
* Casper client-side helpers.
*/
ClientUtils
=
function
ClientUtils
()
{
exports
.
ClientUtils
=
function
ClientUtils
()
{
var
BASE64_ENCODE_CHARS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
var
BASE64_DECODE_CHARS
=
new
Array
(
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
...
...
@@ -553,7 +553,6 @@
}
};
};
exports
.
ClientUtils
=
ClientUtils
;
// silly "hack" to force having an instance available
exports
.
__utils__
=
new
exports
.
ClientUtils
();
...
...
samples/cliplay.coffee
View file @
2af64a1
...
...
@@ -6,7 +6,9 @@ casper.cli.drop "cli"
casper
.
cli
.
drop
"casper-path"
if
casper
.
cli
.
args
.
length
is
0
and
Object
.
keys
(
casper
.
cli
.
options
).
length
is
0
casper
.
echo
(
"Pass some args and options to see how they are handled by CasperJS"
).
exit
()
casper
.
echo
(
"Pass some args and options to see how they are handled by CasperJS"
)
.
exit
(
1
)
casper
.
echo
"Casper CLI passed args:"
dump
casper
.
cli
.
args
...
...
samples/cliplay.js
View file @
2af64a1
...
...
@@ -6,7 +6,10 @@ casper.cli.drop("cli");
casper
.
cli
.
drop
(
"casper-path"
);
if
(
casper
.
cli
.
args
.
length
===
0
&&
Object
.
keys
(
casper
.
cli
.
options
).
length
===
0
)
{
casper
.
echo
(
"Pass some args and options to see how they are handled by CasperJS"
).
exit
();
casper
.
echo
(
"Pass some args and options to see how they are handled by CasperJS"
)
.
exit
(
1
)
;
}
casper
.
echo
(
"Casper CLI passed args:"
);
...
...
samples/customlogging.coffee
View file @
2af64a1
""" A basic custom logging implementation. The idea is to (extremely) verbosely
log every received resource.
"""
###
A basic custom logging implementation. The idea is to (extremely) verbosely
log every received resource.
###
casper
=
require
(
'casper'
).
create
# Every time a resource is received, a new log entry is added to the stack
...
...
samples/googlematch.coffee
View file @
2af64a1
...
...
@@ -20,8 +20,9 @@ casper.fetchScore = ->
terms
=
casper
.
cli
.
args
# terms are passed through command-line arguments
if
terms
.
length
<
3
casper
.
echo
'Usage: casperjs googlematch.js term1, term2 [, term3]...'
casper
.
exit
()
casper
.
echo
'Usage: casperjs googlematch.js term1, term2 [, term3]...'
.
exit
(
1
)
scores
=
[]
...
...
samples/googlematch.js
View file @
2af64a1
...
...
@@ -21,7 +21,10 @@ casper.fetchScore = function() {
};
if
(
terms
.
length
<
2
)
{
casper
.
echo
(
'Usage: casperjs googlematch.js term1, term2 [, term3]...'
).
exit
();
casper
.
echo
(
'Usage: casperjs googlematch.js term1, term2 [, term3]...'
)
.
exit
(
1
)
;
}
casper
.
echo
(
'Let the match begin!'
);
...
...
samples/googlepagination.coffee
View file @
2af64a1
...
...
@@ -8,8 +8,9 @@ casper = require('casper').create()
currentPage
=
1
if
casper
.
cli
.
args
.
length
==
0
casper
.
echo
"usage: $ casperjs my search terms"
casper
.
exit
()
casper
.
echo
"usage: $ casperjs my search terms"
.
exit
(
1
)
processPage
=
->
@
echo
"capturing page
#{
currentPage
}
"
...
...
samples/googlepagination.js
View file @
2af64a1
...
...
@@ -4,8 +4,10 @@ casper = require('casper').create();
currentPage
=
1
;
if
(
casper
.
cli
.
args
.
length
===
0
)
{
casper
.
echo
(
"usage: $ casperjs my search terms"
);
casper
.
exit
();
casper
.
echo
(
"usage: $ casperjs my search terms"
)
.
exit
(
1
)
;
}
processPage
=
function
()
{
...
...
samples/metaextract.coffee
View file @
2af64a1
...
...
@@ -3,8 +3,9 @@ url = casper.cli.get 0
metas
=
[]
if
not
url
casper
.
echo
"Usage: casperjs [url]"
casper
.
exit
()
casper
.
echo
"Usage: casperjs [url]"
.
exit
(
1
)
casper
.
start
url
,
->
metas
=
@
evaluate
->
...
...
samples/metaextract.js
View file @
2af64a1
...
...
@@ -3,7 +3,10 @@ var casper = require("casper").create()
,
metas
=
[];
if
(
!
url
)
{
casper
.
echo
(
'Usage: casperjs [url]'
).
exit
();
casper
.
echo
(
'Usage: casperjs [url]'
)
.
exit
(
1
)
;
}
casper
.
start
(
url
,
function
()
{
...
...
samples/screenshot.coffee
View file @
2af64a1
...
...
@@ -11,8 +11,9 @@ twitterAccount = casper.cli.get 0
filename
=
casper
.
cli
.
get
1
if
not
twitterAccount
or
not
filename
or
not
/\.(png|jpg|pdf)$/i
.
test
filename
casper
.
echo
"Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>"
casper
.
exit
()
casper
.
echo
"Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>"
.
exit
(
1
)
casper
.
start
"https://twitter.com/#!/
#{
twitterAccount
}
"
,
->
capture
=
->
...
...
samples/screenshot.js
View file @
2af64a1
...
...
@@ -14,8 +14,10 @@ var twitterAccount = casper.cli.get(0);
var
filename
=
casper
.
cli
.
get
(
1
);
if
(
!
twitterAccount
||
!
filename
||
!
/
\.(
png|jpg|pdf
)
$/i
.
test
(
filename
))
{
casper
.
echo
(
"Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>"
);
casper
.
exit
();
casper
.
echo
(
"Usage $ casperjs samples/screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>"
)
.
exit
(
1
)
;
}
casper
.
start
(
'https://twitter.com/#!/'
+
twitterAccount
,
function
()
{
...
...
samples/timeout.coffee
View file @
2af64a1
...
...
@@ -21,8 +21,9 @@ casper = require('casper').create
timeout
=
~~
casper
.
cli
.
get
0
if
timeout
<
1
casper
.
echo
"You must pass a valid timeout value"
casper
.
exit
()
casper
.
echo
"You must pass a valid timeout value"
.
exit
(
1
)
casper
.
echo
"Will google.com load in less than
#{
timeout
}
ms?"
casper
.
options
.
timeout
=
timeout
...
...
samples/timeout.js
View file @
2af64a1
...
...
@@ -22,7 +22,10 @@ var casper = require('casper').create({
var
timeout
=
~~
casper
.
cli
.
get
(
0
);
if
(
timeout
<
1
)
{
casper
.
echo
(
'You must pass a valid timeout value'
).
exit
();
casper
.
echo
(
'You must pass a valid timeout value'
)
.
exit
(
1
)
;
}
casper
.
echo
(
'Will google.com load in less than '
+
timeout
+
'ms?'
);
casper
.
options
.
timeout
=
timeout
;
...
...
Please
register
or
sign in
to post a comment