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
125db333
...
125db3336269714a4278ddeeb53f097f37ad5c73
authored
2012-05-21 12:18:44 +0200
by
Brikou CARRE
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
converted most single quote to double quote
1 parent
000df9f4
Show whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
100 additions
and
100 deletions
samples/bbcshots.coffee
samples/bbcshots.js
samples/customevents.coffee
samples/customevents.js
samples/customlogging.coffee
samples/customlogging.js
samples/download.coffee
samples/download.js
samples/dynamic.coffee
samples/dynamic.js
samples/each.coffee
samples/each.js
samples/events.coffee
samples/events.js
samples/extends.coffee
samples/extends.js
samples/googlelinks.coffee
samples/googlelinks.js
samples/googlematch.coffee
samples/googlematch.js
samples/googlepagination.coffee
samples/googlepagination.js
samples/googletesting.coffee
samples/googletesting.js
samples/logcolor.coffee
samples/logcolor.js
samples/metaextract.js
samples/multirun.coffee
samples/multirun.js
samples/screenshot.coffee
samples/screenshot.js
samples/statushandlers.coffee
samples/statushandlers.js
samples/steptimeout.coffee
samples/steptimeout.js
samples/timeout.coffee
samples/timeout.js
samples/bbcshots.coffee
View file @
125db33
...
...
@@ -2,7 +2,7 @@
Create a mosaic image from all headline photos on BBC homepage
###
casper
=
require
(
'casper'
).
create
()
casper
=
require
(
"casper"
).
create
()
nbLinks
=
0
currentLink
=
1
images
=
[]
...
...
@@ -13,7 +13,7 @@ casper.hide = (selector) ->
document
.
querySelector
(
selector
).
style
.
display
=
"none"
,
selector
:
selector
casper
.
start
'http://www.bbc.co.uk/'
,
->
casper
.
start
"http://www.bbc.co.uk/"
,
->
nbLinks
=
@
evaluate
->
return
__utils__
.
findAll
(
'#promo2_carousel_items_items li'
).
length
@
echo
"
#{
nbLinks
}
items founds"
...
...
@@ -22,12 +22,12 @@ casper.start 'http://www.bbc.co.uk/', ->
@
hide
'.nav_right'
@
mouse
.
move
'#promo2_carousel'
@
waitUntilVisible
'.autoplay.nav_pause'
,
->
@
echo
'Moving over pause button'
@
echo
"Moving over pause button"
@
mouse
.
move
'.autoplay.nav_pause'
@
click
'.autoplay.nav_pause'
@
echo
'Clicked on pause button'
@
click
".autoplay.nav_pause"
@
echo
"Clicked on pause button"
@
waitUntilVisible
'.autoplay.nav_play'
,
->
@
echo
'Carousel has been paused'
@
echo
"Carousel has been paused"
# hide play button
@
hide
'.autoplay'
...
...
@@ -47,8 +47,8 @@ next = ->
# Building resulting page and image
buildPage
=
->
@
echo
'Build result page'
fs
=
require
'fs'
@
echo
"Build result page"
fs
=
require
"fs"
@
viewport
624
,
400
pageHtml
=
"<html><body style='background:black;margin:0;padding:0'>"
for
image
in
images
...
...
@@ -56,7 +56,7 @@ buildPage = ->
pageHtml
+=
"</body></html>"
fs
.
write
'result.html'
,
pageHtml
,
'w'
@
thenOpen
"file://
#{
fs
.
workingDirectory
}
/result.html"
,
->
@
echo
'Resulting image saved to result.png'
@
echo
"Resulting image saved to result.png"
@
capture
'result.png'
casper
.
then
next
...
...
samples/bbcshots.js
View file @
125db33
...
...
@@ -2,7 +2,7 @@
Create a mosaic image from all headline photos on BBC homepage
*/
var
casper
=
require
(
'casper'
).
create
();
var
casper
=
require
(
"casper"
).
create
();
var
nbLinks
=
0
;
var
currentLink
=
1
;
var
images
=
[];
...
...
@@ -15,7 +15,7 @@ casper.hide = function(selector) {
});
};
casper
.
start
(
'http://www.bbc.co.uk/'
,
function
()
{
casper
.
start
(
"http://www.bbc.co.uk/"
,
function
()
{
nbLinks
=
this
.
evaluate
(
function
()
{
return
__utils__
.
findAll
(
'#promo2_carousel_items_items li'
).
length
;
});
...
...
@@ -25,12 +25,12 @@ casper.start('http://www.bbc.co.uk/', function() {
this
.
hide
(
'.nav_right'
);
this
.
mouse
.
move
(
'#promo2_carousel'
);
this
.
waitUntilVisible
(
'.autoplay.nav_pause'
,
function
()
{
this
.
echo
(
'Moving over pause button'
);
this
.
echo
(
"Moving over pause button"
);
this
.
mouse
.
move
(
'.autoplay.nav_pause'
);
this
.
click
(
'.autoplay.nav_pause'
);
this
.
echo
(
'Clicked on pause button'
);
this
.
click
(
".autoplay.nav_pause"
);
this
.
echo
(
"Clicked on pause button"
);
this
.
waitUntilVisible
(
'.autoplay.nav_play'
,
function
()
{
this
.
echo
(
'Carousel has been paused'
);
this
.
echo
(
"Carousel has been paused"
);
// hide play button
this
.
hide
(
'.autoplay'
);
});
...
...
@@ -54,8 +54,8 @@ var next = function next() {
};
var
buildPage
=
function
buildPage
()
{
this
.
echo
(
'Build result page'
);
var
fs
=
require
(
'fs'
);
this
.
echo
(
"Build result page"
);
var
fs
=
require
(
"fs"
);
this
.
viewport
(
624
,
400
);
var
pageHtml
=
"<html><body style='background:black;margin:0;padding:0'>"
;
images
.
forEach
(
function
(
image
)
{
...
...
@@ -64,7 +64,7 @@ var buildPage = function buildPage() {
pageHtml
+=
"</body></html>"
;
fs
.
write
(
'result.html'
,
pageHtml
,
'w'
);
this
.
thenOpen
(
"file://"
+
fs
.
workingDirectory
+
"/result.html"
,
function
()
{
this
.
echo
(
'Resulting image saved to result.png'
);
this
.
echo
(
"Resulting image saved to result.png"
);
this
.
capture
(
'result.png'
);
});
};
...
...
samples/customevents.coffee
View file @
125db33
casper
=
require
(
'casper'
).
create
()
casper
=
require
(
"casper"
).
create
()
# listening to a custom event
casper
.
on
'google.loaded'
,
(
title
)
->
casper
.
echo
"Google page title is
#{
title
}
"
casper
.
start
'http://google.com/'
,
->
casper
.
start
"http://google.com/"
,
->
# emitting a custom event
@
emit
'google.loaded'
,
@
getTitle
()
...
...
samples/customevents.js
View file @
125db33
var
casper
=
require
(
'casper'
).
create
();
var
casper
=
require
(
"casper"
).
create
();
// listening to a custom event
casper
.
on
(
'google.loaded'
,
function
(
title
)
{
casper
.
echo
(
"Google page title is "
+
title
);
});
casper
.
start
(
'http://google.com/'
,
function
()
{
casper
.
start
(
"http://google.com/"
,
function
()
{
// emitting a custom event
this
.
emit
(
'google.loaded'
,
this
.
getTitle
());
});
...
...
samples/customlogging.coffee
View file @
125db33
...
...
@@ -3,7 +3,7 @@ A basic custom logging implementation. The idea is to (extremely) verbosely
log every received resource.
###
casper
=
require
(
'casper'
).
create
casper
=
require
(
"casper"
).
create
# Every time a resource is received, a new log entry is added to the stack
# at the 'verbose' level.
onResourceReceived
:
(
self
,
resource
)
->
...
...
@@ -20,5 +20,5 @@ casper = require('casper').create
casper
.
logLevels
=
[
'verbose'
].
concat
casper
.
logLevels
# test our new logger with google
casper
.
start
'http://www.google.com/'
casper
.
start
"http://www.google.com/"
casper
.
run
()
...
...
samples/customlogging.js
View file @
125db33
...
...
@@ -3,7 +3,7 @@ A basic custom logging implementation. The idea is to (extremely) verbosely
log every received resource.
*/
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
/**
* Every time a resource is received, a new log entry is added to the stack
* at the 'verbose' level.
...
...
@@ -31,6 +31,6 @@ var casper = require('casper').create({
casper
.
logLevels
=
[
'verbose'
].
concat
(
casper
.
logLevels
);
// test our new logger with google
casper
.
start
(
'http://www.google.com/'
).
run
(
function
(
self
)
{
casper
.
start
(
"http://www.google.com/"
).
run
(
function
(
self
)
{
self
.
exit
();
});
...
...
samples/download.coffee
View file @
125db33
...
...
@@ -2,9 +2,9 @@
Download the google logo image as base64
###
casper
=
require
(
'casper'
).
create
verbose
:
true
casper
=
require
(
"casper"
).
create
verbose
:
true
casper
.
start
'http://www.google.fr/'
,
->
@
echo
@
base64encode
'http://www.google.fr/images/srpr/logo3w.png'
casper
.
start
"http://www.google.fr/"
,
->
@
echo
@
base64encode
"http://www.google.fr/images/srpr/logo3w.png"
casper
.
run
()
...
...
samples/download.js
View file @
125db33
...
...
@@ -2,12 +2,12 @@
Download the google logo image as base64
*/
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
});
casper
.
start
(
'http://www.google.fr/'
,
function
()
{
this
.
echo
(
this
.
base64encode
(
'http://www.google.fr/images/srpr/logo3w.png'
));
casper
.
start
(
"http://www.google.fr/"
,
function
()
{
this
.
echo
(
this
.
base64encode
(
"http://www.google.fr/images/srpr/logo3w.png"
));
});
casper
.
run
();
...
...
samples/dynamic.coffee
View file @
125db33
casper
=
require
(
'casper'
).
create
verbose
:
true
casper
=
require
(
"casper"
).
create
verbose
:
true
# If we don't set a limit, it could go on forever
upTo
=
~~
casper
.
cli
.
get
(
0
)
||
10
# max 10 links
...
...
@@ -35,7 +35,7 @@ addLinks = (link) ->
casper
.
start
()
casper
.
then
->
@
echo
'Starting'
casper
.
then
->
@
echo
"Starting"
currentLink
=
0
;
...
...
@@ -48,7 +48,7 @@ check = ->
currentLink
++
@
run
check
else
@
echo
'All done.'
@
echo
"All done."
@
exit
()
casper
.
run
check
...
...
samples/dynamic.js
View file @
125db33
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
});
...
...
@@ -44,7 +44,7 @@ var addLinks = function addLinks(link) {
casper
.
start
();
casper
.
then
(
function
()
{
this
.
echo
(
'Starting'
);
this
.
echo
(
"Starting"
);
});
var
currentLink
=
0
;
...
...
@@ -58,7 +58,7 @@ var check = function check() {
currentLink
++
;
this
.
run
(
check
);
}
else
{
this
.
echo
(
'All done.'
);
this
.
echo
(
"All done."
);
this
.
exit
();
}
};
...
...
samples/each.coffee
View file @
125db33
casper
=
require
(
'casper'
).
create
()
casper
=
require
(
"casper"
).
create
()
links
=
[
'http://google.com/'
...
...
samples/each.js
View file @
125db33
var
casper
=
require
(
'casper'
).
create
();
var
casper
=
require
(
"casper"
).
create
();
var
links
=
[
'http://google.com/'
,
...
...
samples/events.coffee
View file @
125db33
casper
=
require
(
'casper'
).
create
()
casper
=
require
(
"casper"
).
create
()
casper
.
on
"http.status.200"
,
(
resource
)
->
@
echo
"
#{
resource
.
url
}
is OK"
,
"INFO"
...
...
samples/events.js
View file @
125db33
...
...
@@ -2,7 +2,7 @@
* This script will add a custom HTTP status code handler, here for 404 pages.
*
*/
var
casper
=
require
(
'casper'
).
create
();
var
casper
=
require
(
"casper"
).
create
();
casper
.
on
(
'http.status.200'
,
function
(
resource
)
{
this
.
echo
(
resource
.
url
+
' is OK'
,
'INFO'
);
...
...
samples/extends.coffee
View file @
125db33
...
...
@@ -4,7 +4,7 @@ links =
'http://www.bbc.co.uk/'
:
0
'http://www.guardian.co.uk/'
:
0
class
Fantomas
extends
require
(
'casper'
).
Casper
class
Fantomas
extends
require
(
"casper"
).
Casper
countLinks
:
->
@
evaluate
->
__utils__
.
findAll
(
'a'
).
length
...
...
samples/extends.js
View file @
125db33
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
loadImages
:
false
,
logLevel
:
"debug"
,
verbose
:
true
...
...
samples/googlelinks.coffee
View file @
125db33
...
...
@@ -3,7 +3,7 @@ getLinks = ->
Array
::
map
.
call
links
,
(
e
)
->
e
.
getAttribute
"href"
links
=
[]
casper
=
require
(
'casper'
).
create
()
casper
=
require
(
"casper"
).
create
()
casper
.
start
"http://google.fr/"
,
->
# search for 'casperjs' from google form
...
...
samples/googlelinks.js
View file @
125db33
...
...
@@ -7,7 +7,7 @@ var getLinks = function getLinks() {
};
var
links
=
[];
var
casper
=
require
(
'casper'
).
create
();
var
casper
=
require
(
"casper"
).
create
();
casper
.
start
(
"http://google.fr/"
,
function
()
{
// search for 'casperjs' from google form
...
...
samples/googlematch.coffee
View file @
125db33
...
...
@@ -10,7 +10,7 @@ Usage:
winner is "nicolas" with 69600000 results
###
casper
=
require
(
'casper'
).
create
verbose
:
true
casper
=
require
(
"casper"
).
create
verbose
:
true
casper
.
fetchScore
=
->
@
evaluate
->
...
...
samples/googlematch.js
View file @
125db33
...
...
@@ -10,7 +10,7 @@ Usage:
winner is "nicolas" with 69600000 results
*/
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
});
...
...
samples/googlepagination.coffee
View file @
125db33
...
...
@@ -6,7 +6,7 @@ Usage: $ casperjs googlepagination.coffee my search terms
(all arguments will be used as the query)
###
casper
=
require
(
'casper'
).
create
()
casper
=
require
(
"casper"
).
create
()
currentPage
=
1
if
casper
.
cli
.
args
.
length
is
0
...
...
@@ -32,7 +32,7 @@ processPage = ->
else
@
echo
"that's all, folks."
casper
.
start
'http://google.fr/'
,
->
casper
.
start
"http://google.fr/"
,
->
@
fill
'form[action="/search"]'
,
q
:
casper
.
cli
.
args
.
join
(
' '
),
true
casper
.
then
processPage
...
...
samples/googlepagination.js
View file @
125db33
...
...
@@ -6,7 +6,7 @@ Usage: $ casperjs googlepagination.coffee my search terms
(all arguments will be used as the query)
*/
var
casper
=
require
(
'casper'
).
create
();
var
casper
=
require
(
"casper"
).
create
();
var
currentPage
=
1
;
...
...
@@ -38,7 +38,7 @@ var processPage = function processPage() {
}
};
casper
.
start
(
'http://google.fr/'
,
function
()
{
casper
.
start
(
"http://google.fr/"
,
function
()
{
return
this
.
fill
(
'form[action="/search"]'
,
{
q
:
casper
.
cli
.
args
.
join
(
' '
)
},
true
);
...
...
samples/googletesting.coffee
View file @
125db33
casper
=
require
(
'casper'
).
create
logLevel
:
"debug"
casper
=
require
(
"casper"
).
create
logLevel
:
"debug"
casper
.
start
'http://www.google.fr/'
,
->
casper
.
start
"http://www.google.fr/"
,
->
@
test
.
assertTitle
'Google'
,
'google homepage title is the one expected'
@
test
.
assertExists
'form[action="/search"]'
,
'main form is found'
@
fill
'form[action="/search"]'
,
q
:
'foo'
,
true
...
...
samples/googletesting.js
View file @
125db33
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
logLevel
:
"debug"
});
casper
.
start
(
'http://www.google.fr/'
,
function
(
self
)
{
casper
.
start
(
"http://www.google.fr/"
,
function
(
self
)
{
self
.
test
.
assertTitle
(
'Google'
,
'google homepage title is the one expected'
);
self
.
test
.
assertExists
(
'form[action="/search"]'
,
'main form is found'
);
self
.
fill
(
'form[action="/search"]'
,
{
...
...
samples/logcolor.coffee
View file @
125db33
casper
=
require
(
'casper'
).
create
casper
=
require
(
"casper"
).
create
verbose
:
true
logLevel
:
'debug'
casper
.
log
'this is a debug message'
,
'debug'
casper
.
log
'and an informative one'
,
'info'
casper
.
log
'and a warning'
,
'warning'
casper
.
log
'and an error'
,
'error'
casper
.
log
"this is a debug message"
,
'debug'
casper
.
log
"and an informative one"
,
'info'
casper
.
log
"and a warning"
,
'warning'
casper
.
log
"and an error"
,
'error'
casper
.
exit
()
...
...
samples/logcolor.js
View file @
125db33
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
,
logLevel
:
'debug'
});
casper
.
log
(
'this is a debug message'
,
'debug'
);
casper
.
log
(
'and an informative one'
,
'info'
);
casper
.
log
(
'and a warning'
,
'warning'
);
casper
.
log
(
'and an error'
,
'error'
);
casper
.
log
(
"this is a debug message"
,
'debug'
);
casper
.
log
(
"and an informative one"
,
'info'
);
casper
.
log
(
"and a warning"
,
'warning'
);
casper
.
log
(
"and an error"
,
'error'
);
casper
.
exit
();
...
...
samples/metaextract.js
View file @
125db33
...
...
@@ -4,7 +4,7 @@ var casper = require("casper").create()
if
(
!
url
)
{
casper
.
echo
(
'Usage: casperjs [url]'
)
.
echo
(
"Usage: casperjs [url]"
)
.
exit
(
1
)
;
}
...
...
samples/multirun.coffee
View file @
125db33
casper
=
require
(
'casper'
).
create
verbose
:
true
casper
=
require
(
"casper"
).
create
verbose
:
true
countLinks
=
->
document
.
querySelectorAll
(
'a'
).
length
suites
=
[
->
@
echo
'Suite 1'
@
start
'http://google.com/'
,
->
@
echo
"Page title:
#{
@
getTitle
()
}
"
@
echo
"Suite 1"
@
start
"http://google.com/"
,
->
@
echo
"Page title:
#{
@
getTitle
()
}
"
@
then
->
@
echo
"
#{
@
evaluate
(
countLinks
)
}
links"
->
@
echo
'Suite 2'
@
start
'http://yahoo.com/'
,
->
@
echo
"Page title:
#{
@
getTitle
()
}
"
@
echo
"Suite 2"
@
start
"http://yahoo.com/"
,
->
@
echo
"Page title:
#{
@
getTitle
()
}
"
@
then
->
@
echo
"
#{
@
evaluate
(
countLinks
)
}
links"
->
@
echo
'Suite 3'
@
start
'http://bing.com/'
,
->
@
echo
"Page title:
#{
@
getTitle
()
}
"
@
echo
"Suite 3"
@
start
"http://bing.com/"
,
->
@
echo
"Page title:
#{
@
getTitle
()
}
"
@
then
->
@
echo
"
#{
@
evaluate
(
countLinks
)
}
links"
]
casper
.
start
()
casper
.
then
->
@
echo
(
'Starting'
)
@
echo
(
"Starting"
)
currentSuite
=
0
;
...
...
samples/multirun.js
View file @
125db33
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
verbose
:
true
});
...
...
@@ -8,24 +8,24 @@ var countLinks = function countLinks() {
var
suites
=
[
function
()
{
this
.
echo
(
'Suite 1'
);
this
.
start
(
'http://google.com/'
,
function
()
{
this
.
echo
(
"Suite 1"
);
this
.
start
(
"http://google.com/"
,
function
()
{
this
.
echo
(
"Page title: "
+
(
this
.
getTitle
()));
});
this
.
then
(
function
()
{
this
.
echo
((
this
.
evaluate
(
countLinks
))
+
" links"
);
});
},
function
()
{
this
.
echo
(
'Suite 2'
);
this
.
start
(
'http://yahoo.com/'
,
function
()
{
this
.
echo
(
"Suite 2"
);
this
.
start
(
"http://yahoo.com/"
,
function
()
{
this
.
echo
(
"Page title: "
+
(
this
.
getTitle
()));
});
this
.
then
(
function
()
{
this
.
echo
((
this
.
evaluate
(
countLinks
))
+
" links"
);
});
},
function
()
{
this
.
echo
(
'Suite 3'
);
this
.
start
(
'http://bing.com/'
,
function
()
{
this
.
echo
(
"Suite 3"
);
this
.
start
(
"http://bing.com/"
,
function
()
{
this
.
echo
(
"Page title: "
+
(
this
.
getTitle
()));
});
this
.
then
(
function
()
{
...
...
@@ -37,7 +37,7 @@ var suites = [
casper
.
start
();
casper
.
then
(
function
()
{
this
.
echo
(
'Starting'
);
this
.
echo
(
"Starting"
);
});
var
currentSuite
=
0
;
...
...
samples/screenshot.coffee
View file @
125db33
...
...
@@ -3,7 +3,7 @@ This script will capture a screenshot of a twitter account page
Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>
###
casper
=
require
(
'casper'
).
create
casper
=
require
(
"casper"
).
create
viewportSize
:
width
:
1024
height
:
768
...
...
samples/screenshot.js
View file @
125db33
...
...
@@ -3,7 +3,7 @@ This script will capture a screenshot of a twitter account page
Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>
*/
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
viewportSize
:
{
width
:
1024
,
height
:
768
...
...
@@ -20,7 +20,7 @@ if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) {
;
}
casper
.
start
(
'https://twitter.com/#!/'
+
twitterAccount
,
function
()
{
casper
.
start
(
"https://twitter.com/#!/"
+
twitterAccount
,
function
()
{
this
.
waitForSelector
(
'.tweet-row'
,
function
()
{
this
.
captureSelector
(
filename
,
'html'
);
this
.
echo
(
"Saved screenshot of "
+
this
.
getCurrentUrl
()
+
" to "
+
filename
);
...
...
samples/statushandlers.coffee
View file @
125db33
...
...
@@ -2,13 +2,13 @@
This script will add a custom HTTP status code handler, here for 404 pages.
###
casper
=
require
(
'casper'
).
create
casper
=
require
(
"casper"
).
create
httpStatusHandlers
:
404
:
(
self
,
resource
)
->
@
echo
"Resource at
#{
resource
.
url
}
not found (404)"
,
"COMMENT"
verbose
:
true
casper
.
start
'http://www.google.com/plop'
,
->
casper
.
start
"http://www.google.com/plop"
,
->
@
echo
"Done."
@
exit
()
...
...
samples/statushandlers.js
View file @
125db33
...
...
@@ -2,7 +2,7 @@
This script will add a custom HTTP status code handler, here for 404 pages.
*/
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
httpStatusHandlers
:
{
404
:
function
(
self
,
resource
)
{
this
.
echo
(
"Resource at "
+
resource
.
url
+
" not found (404)"
,
"COMMENT"
);
...
...
@@ -11,7 +11,7 @@ var casper = require('casper').create({
verbose
:
true
});
casper
.
start
(
'http://www.google.com/plop'
,
function
()
{
casper
.
start
(
"http://www.google.com/plop"
,
function
()
{
this
.
echo
(
"Done."
);
this
.
exit
();
});
...
...
samples/steptimeout.coffee
View file @
125db33
failed
=
[];
casper
=
require
(
'casper'
).
create
casper
=
require
(
"casper"
).
create
onStepTimeout
:
->
failed
.
push
@
requestUrl
links
=
[
...
...
samples/steptimeout.js
View file @
125db33
var
failed
=
[];
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
onStepTimeout
:
function
()
{
failed
.
push
(
this
.
requestUrl
);
}
...
...
samples/timeout.coffee
View file @
125db33
...
...
@@ -15,9 +15,9 @@ Will google.com load in less than 2000ms?
YES!
###
casper
=
require
(
'casper'
).
create
casper
=
require
(
"casper"
).
create
onTimeout
:
->
@
echo
'NOPE.'
,
'RED_BAR'
@
echo
"NOPE."
,
'RED_BAR'
@
exit
()
timeout
=
~~
casper
.
cli
.
get
0
...
...
@@ -29,8 +29,8 @@ if timeout < 1
casper
.
echo
"Will google.com load in less than
#{
timeout
}
ms?"
casper
.
options
.
timeout
=
timeout
casper
.
start
'http://www.google.com/'
,
->
@
echo
'YES!'
,
'GREEN_BAR'
casper
.
start
"http://www.google.com/"
,
->
@
echo
"YES!"
,
'GREEN_BAR'
@
exit
()
casper
.
run
()
\ No newline at end of file
...
...
samples/timeout.js
View file @
125db33
...
...
@@ -15,10 +15,10 @@ Will google.com load in less than 2000ms?
YES!
*/
var
casper
=
require
(
'casper'
).
create
({
var
casper
=
require
(
"casper"
).
create
({
onTimeout
:
function
()
{
this
.
echo
(
'NOPE.'
,
'RED_BAR'
)
.
echo
(
"NOPE."
,
'RED_BAR'
)
.
exit
()
;
}
...
...
@@ -35,9 +35,9 @@ if (timeout < 1) {
casper
.
echo
(
"Will google.com load in less than "
+
timeout
+
"ms?"
);
casper
.
options
.
timeout
=
timeout
;
casper
.
start
(
'http://www.google.com/'
,
function
()
{
casper
.
start
(
"http://www.google.com/"
,
function
()
{
this
.
echo
(
'YES!'
,
'GREEN_BAR'
)
.
echo
(
"YES!"
,
'GREEN_BAR'
)
.
exit
()
;
});
...
...
Please
register
or
sign in
to post a comment