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
64d7050f
...
64d7050f3e9f8de4f4cc9cde1d6f6a8fb808cfd8
authored
2013-02-22 08:39:27 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed #387 - Setting viewport isn't quite synchronous
1 parent
63367591
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
5 deletions
CHANGELOG.md
modules/casper.js
tests/suites/casper/viewport.js
CHANGELOG.md
View file @
64d7050
...
...
@@ -66,6 +66,7 @@ Last, all the casper test suites have been upgraded to use the new testing featu
-
closed
[
#392
](
https://github.com/n1k0/casperjs/issues/392
)
-
`--direct`
&
`--log-level`
options available for the
`casperjs`
executable
-
closed
[
#350
](
https://github.com/n1k0/casperjs/issues/350
)
- Add a Casper.waitForSelectorTextChange() method
-
fixed
[
#387
](
https://github.com/n1k0/casperjs/issues/387
)
- Setting viewport isn't quite synchronous
2013-02-08, v1.0.2
------------------
...
...
modules/casper.js
View file @
64d7050
...
...
@@ -1645,13 +1645,15 @@ Casper.prototype.userAgent = function userAgent(agent) {
};
/**
* Changes the current viewport size.
* Changes the current viewport size. That operation is asynchronous as the page
* has to reflow its contents accordingly.
*
* @param Number width The viewport width, in pixels
* @param Number height The viewport height, in pixels
* @param Number width The viewport width, in pixels
* @param Number height The viewport height, in pixels
* @param Function then Next step to process (optional)
* @return Casper
*/
Casper
.
prototype
.
viewport
=
function
viewport
(
width
,
height
)
{
Casper
.
prototype
.
viewport
=
function
viewport
(
width
,
height
,
then
)
{
"use strict"
;
this
.
checkStarted
();
if
(
!
utils
.
isNumber
(
width
)
||
!
utils
.
isNumber
(
height
)
||
width
<=
0
||
height
<=
0
)
{
...
...
@@ -1662,7 +1664,7 @@ Casper.prototype.viewport = function viewport(width, height) {
height
:
height
};
this
.
emit
(
'viewport.changed'
,
[
width
,
height
]);
return
this
;
return
utils
.
isFunction
(
then
)
?
this
.
then
(
then
)
:
this
;
};
/**
...
...
tests/suites/casper/viewport.js
View file @
64d7050
/*global casper*/
/*jshint strict:false*/
var
utils
=
require
(
'utils'
);
casper
.
test
.
begin
(
'viewport() tests'
,
3
,
function
(
test
)
{
casper
.
start
();
casper
.
viewport
(
1337
,
999
);
...
...
@@ -11,3 +13,22 @@ casper.test.begin('viewport() tests', 3, function(test) {
'Casper.viewport() validates viewport size data'
);
test
.
done
();
});
casper
.
test
.
begin
(
'viewport() asynchronous tests'
,
2
,
function
(
test
)
{
var
screenshotData
;
casper
.
start
(
'tests/site/index.html'
).
viewport
(
800
,
600
,
function
()
{
this
.
setContent
(
utils
.
format
(
'<img src="data:image/png;base64,%s">'
,
this
.
captureBase64
(
'png'
)));
});
casper
.
then
(
function
()
{
var
imgInfo
=
this
.
getElementInfo
(
'img'
);
test
.
assertEquals
(
imgInfo
.
width
,
800
,
'Casper.viewport() changes width asynchronously'
);
test
.
assertEquals
(
imgInfo
.
height
,
600
,
'Casper.viewport() changes height asynchronously'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
...
...
Please
register
or
sign in
to post a comment