Commit 6407ef35 6407ef350468b9210bc15e88f5b0e18c2b8a7363 by Nicolas Perriault

better usability of Casper.viewport()

1 parent 8168fe03
......@@ -675,11 +675,18 @@
/**
* Changes the current viewport size.
*
* @param Object viewportSize An objet with two props: width and height
* @param Number width The viewport width, in pixels
* @param Number height The viewport height, in pixels
* @return Casper
*/
viewport: function(viewportSize) {
this.page.viewportSize = viewportSize;
viewport: function(width, height) {
if (typeof width !== "number" || typeof height !== "number" || width <= 0 || height <= 0) {
throw new Error("Invalid viewport width/height set: " + width + 'x' + height);
}
this.page.viewportSize = {
width: width,
height: height
};
return this;
},
......
......@@ -51,10 +51,10 @@ casper.test.assert(casper.steps.length === 1, 'start() can add a new navigation
// Casper.viewport()
casper.test.comment('viewport');
casper.viewport({width: 1337, height: 999});
casper.test.assertEquals(casper.page.viewportSize.width, 1337, 'Casper.viewport() can change the width of the viewport');
casper.test.assertEquals(casper.page.viewportSize.height, 999, 'Casper.viewport() can change the height of the viewport');
casper.test.assertRaises(casper.viewport, 'booh', 'Casper.viewport() validates viewport size data');
casper.viewport(1337, 999);
casper.test.assertEquals(casper.page.viewportSize.width, 1337, 'Casper.viewport() can change the width of page viewport');
casper.test.assertEquals(casper.page.viewportSize.height, 999, 'Casper.viewport() can change the height of page viewport');
casper.test.assertRaises(casper.viewport, ['a', 'b'], 'Casper.viewport() validates viewport size data');
// Casper#then()
casper.test.comment('then');
......