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
3792ff6e
...
3792ff6ed8c6a584d830229ac45be3ea40b08bcd
authored
2012-01-16 21:45:12 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added new sample: bbcshots.(js|coffee)
1 parent
6c266ac5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
0 deletions
samples/bbcshots.coffee
samples/bbcshots.js
samples/bbcshots.coffee
0 → 100644
View file @
3792ff6
### Create a mosaic image from all headline photos on BBC homepage
###
casper
=
require
(
'casper'
).
create
()
nbLinks
=
0
currentLink
=
1
images
=
[]
casper
.
start
'http://www.bbc.co.uk/'
,
->
nbLinks
=
@
evaluate
->
return
__utils__
.
findAll
(
'#carousel_items_items li'
).
length
@
echo
"
#{
nbLinks
}
items founds"
# hide navigation arrows
@
evaluate
->
document
.
querySelector
(
'.nav_left'
).
style
.
display
=
"none"
document
.
querySelector
(
'.nav_right'
).
style
.
display
=
"none"
@
mouse
.
move
'#promo_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
@
evaluate
->
document
.
querySelector
(
'.autoplay'
).
style
.
display
=
"none"
# Building resulting page and image
buildPage
=
->
this
.
echo
'Build result page'
fs
=
require
'fs'
@
viewport
624
,
400
pageHtml
=
"<html bgcolor=black><body>"
images
.
forEach
(
image
)
->
pageHtml
+=
"<img src='file://
#{
fs
.
workingDirectory
}
/
#{
image
}
'><br>"
pageHtml
+=
"</body></html>"
fs
.
write
'result.html'
,
pageHtml
,
'w'
@
thenOpen
"file://
#{
fs
.
workingDirectory
}
/result.html"
,
->
this
.
echo
'Resulting image saved to result.png'
this
.
capture
'result.png'
# Capture carrousel area
next
=
->
image
=
"bbcshot
#{
currentLink
}
.png"
images
.
push
image
@
echo
"Processing image
#{
currentLink
}
"
@
captureSelector
image
,
'.carousel_viewport'
if
currentLink
<
nbLinks
@
click
".carousel_itemList_li[rel='
#{
currentLink
}
']"
@
wait
1000
,
->
this
.
then
next
currentLink
++
else
this
.
then
buildPage
casper
.
then
next
casper
.
run
()
samples/bbcshots.js
0 → 100644
View file @
3792ff6
/**
* Create a mosaic image from all headline photos on BBC homepage
*
*/
var
casper
=
require
(
'casper'
).
create
(),
nbLinks
=
0
,
currentLink
=
1
,
images
=
[];
casper
.
start
(
'http://www.bbc.co.uk/'
,
function
()
{
nbLinks
=
this
.
evaluate
(
function
()
{
return
__utils__
.
findAll
(
'#carousel_items_items li'
).
length
;
});
this
.
echo
(
nbLinks
+
' items founds'
);
// hide navigation arrows
this
.
evaluate
(
function
()
{
document
.
querySelector
(
'.nav_left'
).
style
.
display
=
"none"
;
document
.
querySelector
(
'.nav_right'
).
style
.
display
=
"none"
;
});
this
.
mouse
.
move
(
'#promo_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
.
evaluate
(
function
()
{
document
.
querySelector
(
'.autoplay'
).
style
.
display
=
"none"
;
});
});
});
});
// Capture carrousel area
var
next
=
function
()
{
var
image
=
'bbcshot'
+
currentLink
+
'.png'
;
images
.
push
(
image
);
this
.
echo
(
'Processing image '
+
currentLink
);
this
.
captureSelector
(
image
,
'.carousel_viewport'
);
if
(
currentLink
<
nbLinks
)
{
this
.
click
(
'.carousel_itemList_li[rel="'
+
currentLink
+
'"]'
);
this
.
wait
(
1000
,
function
()
{
this
.
then
(
next
);
currentLink
++
;
});
}
else
{
this
.
then
(
buildPage
);
}
};
// Building resulting page and image
var
buildPage
=
function
()
{
this
.
echo
(
'Build result page'
);
var
fs
=
require
(
'fs'
);
this
.
viewport
(
624
,
400
);
var
pageHtml
=
"<html bgcolor=black><body>"
;
images
.
forEach
(
function
(
image
)
{
pageHtml
+=
'<img src="file://'
+
fs
.
workingDirectory
+
'/'
+
image
+
'"><br>'
;
});
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
.
capture
(
'result.png'
);
});
};
casper
.
then
(
next
);
casper
.
run
();
Please
register
or
sign in
to post a comment