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
0cef17ee
...
0cef17eea509dd23ee8e70ba53fd97bca427672f
authored
2012-12-21 22:40:34 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #325
1 parent
19d0f4c2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
66 deletions
samples/bbcshots.coffee
samples/bbcshots.js
samples/customlogging.coffee
samples/customlogging.js
samples/googlematch.coffee
samples/googlematch.js
samples/bbcshots.coffee
View file @
0cef17e
...
...
@@ -21,15 +21,16 @@ casper.start "http://www.bbc.co.uk/", ->
@
hide
".nav_left"
@
hide
".nav_right"
@
mouse
.
move
"#promo2_carousel"
@
waitUntilVisible
".autoplay.nav_pause"
,
->
@
echo
"Moving over pause button"
@
mouse
.
move
".autoplay.nav_pause"
@
click
".autoplay.nav_pause"
@
echo
"Clicked on pause button"
@
waitUntilVisible
".autoplay.nav_play"
,
->
@
echo
"Carousel has been paused"
# hide play button
@
hide
".autoplay"
casper
.
waitUntilVisible
".autoplay.nav_pause"
,
->
@
echo
"Moving over pause button"
@
mouse
.
move
".autoplay.nav_pause"
@
click
".autoplay.nav_pause"
@
echo
"Clicked on pause button"
@
waitUntilVisible
".autoplay.nav_play"
,
->
@
echo
"Carousel has been paused"
# hide play button
@
hide
".autoplay"
# Capture carrousel area
next
=
->
...
...
samples/bbcshots.js
View file @
0cef17e
...
...
@@ -28,16 +28,17 @@ casper.start("http://www.bbc.co.uk/", function() {
this
.
hide
(
".nav_left"
);
this
.
hide
(
".nav_right"
);
this
.
mouse
.
move
(
"#promo2_carousel"
);
this
.
waitUntilVisible
(
".autoplay.nav_pause"
,
function
()
{
this
.
echo
(
"Moving over pause button"
);
this
.
mouse
.
move
(
".autoplay.nav_pause"
);
this
.
click
(
".autoplay.nav_pause"
);
this
.
echo
(
"Clicked on pause button"
);
this
.
waitUntilVisible
(
".autoplay.nav_play"
,
function
()
{
this
.
echo
(
"Carousel has been paused"
);
// hide play button
this
.
hide
(
".autoplay"
);
});
});
casper
.
waitUntilVisible
(
".autoplay.nav_pause"
,
function
()
{
this
.
echo
(
"Moving over pause button"
);
this
.
mouse
.
move
(
".autoplay.nav_pause"
);
this
.
click
(
".autoplay.nav_pause"
);
this
.
echo
(
"Clicked on pause button"
);
this
.
waitUntilVisible
(
".autoplay.nav_play"
,
function
()
{
this
.
echo
(
"Carousel has been paused"
);
// hide play button
this
.
hide
(
".autoplay"
);
});
});
...
...
samples/customlogging.coffee
View file @
0cef17e
...
...
@@ -2,29 +2,27 @@
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
at the 'verbose' level.
@param Object resource A phantomjs resource object
###
onResourceReceived
:
(
self
,
resource
)
->
infos
=
[]
props
=
[
"url"
"status"
"statusText"
"redirectURL"
"bodySize"
]
infos
.
push
resource
[
prop
]
for
prop
in
props
infos
.
push
"[
#{
header
.
name
}
:
#{
header
.
value
}
]"
for
header
in
resource
.
headers
@
log
infos
.
join
(
", "
),
"verbose"
verbose
:
true
# we want to see the log printed out to the console
logLevel
:
"verbose"
# of course we want to see logs to our new level :)
###
Every time a resource is received, a new log entry is added to the stack
at the 'verbose' level.
###
casper
.
on
'resource.received'
,
(
resource
)
->
infos
=
[]
props
=
[
"url"
"status"
"statusText"
"redirectURL"
"bodySize"
]
infos
.
push
resource
[
prop
]
for
prop
in
props
infos
.
push
"[
#{
header
.
name
}
:
#{
header
.
value
}
]"
for
header
in
resource
.
headers
@
log
infos
.
join
(
", "
),
"verbose"
# add a new 'verbose' logging level at the lowest priority
casper
.
logLevels
=
[
"verbose"
].
concat
casper
.
logLevels
...
...
samples/customlogging.js
View file @
0cef17e
...
...
@@ -5,37 +5,33 @@
* A basic custom logging implementation. The idea is to (extremely) verbosely
* log every received resource.
*/
var
casper
=
require
(
"casper"
).
create
({
/*
Every time a resource is received, a new log entry is added to the stack at
the 'verbose' level.
*/
onResourceReceived
:
function
(
self
,
resource
)
{
var
header
,
infos
,
prop
,
props
,
_i
,
_j
,
_len
,
_len1
,
_ref
;
infos
=
[];
props
=
[
"url"
,
"status"
,
"statusText"
,
"redirectURL"
,
"bodySize"
];
for
(
_i
=
0
,
_len
=
props
.
length
;
_i
<
_len
;
_i
++
)
{
prop
=
props
[
_i
];
infos
.
push
(
resource
[
prop
]);
}
_ref
=
resource
.
headers
;
for
(
_j
=
0
,
_len1
=
_ref
.
length
;
_j
<
_len1
;
_j
++
)
{
header
=
_ref
[
_j
];
infos
.
push
(
"["
+
header
.
name
+
": "
+
header
.
value
+
"]"
);
}
this
.
log
(
infos
.
join
(
", "
),
"verbose"
);
},
verbose
:
true
,
logLevel
:
"verbose"
});
/**
* Every time a resource is received, a new log entry is added to the stack at
* the 'verbose' level.
*/
casper
.
on
(
'resource.received'
,
function
(
resource
)
{
var
infos
=
[];
var
props
=
[
"url"
,
"status"
,
"statusText"
,
"redirectURL"
,
"bodySize"
];
props
.
forEach
(
function
(
prop
)
{
infos
.
push
(
resource
[
prop
]);
});
resource
.
headers
.
forEach
(
function
(
header
)
{
infos
.
push
(
"["
+
header
.
name
+
": "
+
header
.
value
+
"]"
);
});
this
.
log
(
infos
.
join
(
", "
),
"verbose"
);
});
// add a new 'verbose' logging level at the lowest priority
casper
.
logLevels
=
[
"verbose"
].
concat
(
casper
.
logLevels
);
...
...
samples/googlematch.coffee
View file @
0cef17e
...
...
@@ -14,7 +14,7 @@ casper = require("casper").create verbose: true
casper
.
fetchScore
=
->
@
evaluate
->
result
=
document
.
querySelector
(
'#resultStats'
).
innerText
result
=
__utils__
.
findOne
(
'#resultStats'
).
innerText
parseInt
/Environ ([0-9\s]{1,}).*/
.
exec
(
result
)[
1
].
replace
(
/\s/g
,
''
)
terms
=
casper
.
cli
.
args
# terms are passed through command-line arguments
...
...
samples/googlematch.js
View file @
0cef17e
...
...
@@ -19,7 +19,7 @@ var casper = require("casper").create({
casper
.
fetchScore
=
function
()
{
return
this
.
evaluate
(
function
()
{
var
result
=
document
.
querySelector
(
'#resultStats'
).
innerText
;
var
result
=
__utils__
.
findOne
(
'#resultStats'
).
innerText
;
return
parseInt
(
/Environ
([
0-9
\s]{1,})
.*/
.
exec
(
result
)[
1
].
replace
(
/
\s
/g
,
''
),
10
);
});
};
...
...
Please
register
or
sign in
to post a comment