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
c9007eb5
...
c9007eb5786ea97a07a858cd396c558f69b37793
authored
2013-11-26 23:06:20 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper#scrollTo & Casper#scrollToBottom
1 parent
ce773a0d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
0 deletions
docs/modules/casper.rst
modules/casper.js
modules/clientutils.js
tests/suites/casper/scroll.js
docs/modules/casper.rst
View file @
c9007eb
...
...
@@ -1453,6 +1453,40 @@ Casper suite **will run**::
Binding
a
callback
to
``
complete
.
error
``
will
trigger
when
the
``
onComplete
``
callback
fails
.
..
index::
Scroll
``
scrollTo
()``
-------------------------------------------------------------------------------
**
Signature:
**
``
scrollTo
(
Number
x
,
Number
y
)``
..
versionadded::
1
.
1-beta3
Scrolls
current
document
to
the
coordinates
defined
by
the
value
of
``
x
``
and
``
y
``
::
casper
.
start
('
http:
//
foo
.
bar
/
home
',
function
()
{
this
.
scrollTo
(
500
,
300
);
});
..
note::
This
operation
is
synchronous
.
..
index::
Scroll
``
scrollToBottom
()``
-------------------------------------------------------------------------------
**
Signature:
**
``
scrollToBottom
()``
..
versionadded::
1
.
1-beta3
Scrolls
current
document
to
its
bottom::
casper
.
start
('
http:
//
foo
.
bar
/
home
',
function
()
{
this
.
scrollToBottom
();
});
..
note::
This
operation
is
synchronous
.
..
index::
Form
``
sendKeys
()``
...
...
modules/casper.js
View file @
c9007eb
...
...
@@ -1600,6 +1600,30 @@ Casper.prototype.sendKeys = function(selector, keys, options) {
};
/**
* Scrolls current document to x, y coordinates.
*
* @param {Number} x X position
* @param {Number} y Y position
* @return {Casper}
*/
Casper
.
prototype
.
scrollTo
=
function
(
x
,
y
)
{
"use strict"
;
this
.
callUtils
(
"scrollTo"
,
x
,
y
);
return
this
;
};
/**
* Scrolls current document up to its bottom.
*
* @return {Casper}
*/
Casper
.
prototype
.
scrollToBottom
=
function
scrollToBottom
()
{
"use strict"
;
this
.
callUtils
(
"scrollToBottom"
);
return
this
;
};
/**
* Sets current page content.
*
* @param String content Desired page content
...
...
modules/clientutils.js
View file @
c9007eb
...
...
@@ -724,6 +724,23 @@
};
/**
* Scrolls current document to x, y coordinates.
*
* @param {Number} x X position
* @param {Number} y Y position
*/
this
.
scrollTo
=
function
scrollTo
(
x
,
y
)
{
window
.
scrollTo
(
parseInt
(
x
||
0
,
10
),
parseInt
(
y
||
0
,
10
));
};
/**
* Scrolls current document up to its bottom.
*/
this
.
scrollToBottom
=
function
scrollToBottom
()
{
this
.
scrollTo
(
0
,
this
.
getDocumentHeight
());
},
/**
* Performs an AJAX request.
*
* @param String url Url.
...
...
tests/suites/casper/scroll.js
0 → 100644
View file @
c9007eb
/*global casper*/
/*jshint strict:false*/
casper
.
test
.
begin
(
'Casper.scrollTo()'
,
2
,
function
(
test
)
{
casper
.
start
().
then
(
function
()
{
this
.
setContent
(
'<div style="width:2000px;height:2000px">large div is large</div>'
);
this
.
scrollTo
(
1000
,
1000
);
test
.
assertEquals
(
this
.
getGlobal
(
"scrollX"
),
1000
,
"scrollTo() scrolls to X position"
);
test
.
assertEquals
(
this
.
getGlobal
(
"scrollY"
),
1000
,
"scrollTo() scrolls to Y position"
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'Casper.scrollToBottom()'
,
1
,
function
(
test
)
{
casper
.
start
().
then
(
function
()
{
this
.
setContent
(
'<div style="height:2000px">long div is long</div>'
);
this
.
scrollToBottom
();
test
.
assertEval
(
function
()
{
/*global __utils__*/
return
__utils__
.
getDocumentHeight
()
-
window
.
innerHeight
===
window
.
scrollY
;
},
"scrollToBottom() scrolls to max Y by default"
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
Please
register
or
sign in
to post a comment