Commit 92f5aebf 92f5aebf92d357ed10aa4aa08b497abd595fe700 by Nicolas Perriault

backport fixes of master

1 parent ae57bcf3
...@@ -149,6 +149,7 @@ Casper.prototype = { ...@@ -149,6 +149,7 @@ Casper.prototype = {
149 */ 149 */
150 capture: function(targetFile, clipRect) { 150 capture: function(targetFile, clipRect) {
151 var previousClipRect; 151 var previousClipRect;
152 targetFile = require('fs').absolute(targetFile);
152 if (clipRect) { 153 if (clipRect) {
153 if (!utils.isType(clipRect, "object")) { 154 if (!utils.isType(clipRect, "object")) {
154 throw new Error("clipRect must be an Object instance."); 155 throw new Error("clipRect must be an Object instance.");
...@@ -159,10 +160,8 @@ Casper.prototype = { ...@@ -159,10 +160,8 @@ Casper.prototype = {
159 } else { 160 } else {
160 this.log('Capturing page to ' + targetFile, "debug"); 161 this.log('Capturing page to ' + targetFile, "debug");
161 } 162 }
162 try { 163 if (!this.page.render(targetFile)) {
163 this.page.render(targetFile); 164 this.log('Failed to save screenshot to ' + targetFile + '; please check permissions', "error");
164 } catch (e) {
165 this.log('Failed to capture screenshot as ' + targetFile + ': ' + e, "error");
166 } 165 }
167 if (previousClipRect) { 166 if (previousClipRect) {
168 this.page.clipRect = previousClipRect; 167 this.page.clipRect = previousClipRect;
...@@ -888,6 +887,9 @@ Casper.prototype = { ...@@ -888,6 +887,9 @@ Casper.prototype = {
888 * @return Casper 887 * @return Casper
889 */ 888 */
890 viewport: function(width, height) { 889 viewport: function(width, height) {
890 if (!this.started) {
891 throw new Error("Casper must be started in order to set viewport at runtime");
892 }
891 if (!utils.isType(width, "number") || !utils.isType(height, "number") || width <= 0 || height <= 0) { 893 if (!utils.isType(width, "number") || !utils.isType(height, "number") || width <= 0 || height <= 0) {
892 throw new Error("Invalid viewport width/height set: " + width + 'x' + height); 894 throw new Error("Invalid viewport width/height set: " + width + 'x' + height);
893 } 895 }
......
1 if (!phantom.casperLoaded) { 1 var casper = require('casper').create({
2 console.log('This script is intended to work with CasperJS, using its executable.');
3 phantom.exit(1);
4 }
5
6 var casper = new phantom.Casper({
7 logLevel: "debug", 2 logLevel: "debug",
8 verbose: true 3 verbose: true,
4 viewportSize: {
5 width: 1024,
6 height: 768
7 }
9 }); 8 });
10 9
11 casper.start('https://twitter.com/#!/twilio', function(self) { 10 casper.start('https://twitter.com/#!/twilio', function(self) {
...@@ -16,4 +15,4 @@ casper.start('https://twitter.com/#!/twilio', function(self) { ...@@ -16,4 +15,4 @@ casper.start('https://twitter.com/#!/twilio', function(self) {
16 15
17 casper.run(function(self) { 16 casper.run(function(self) {
18 self.exit(); 17 self.exit();
19 });
...\ No newline at end of file ...\ No newline at end of file
18 });
......