Skip to content

Commit

Permalink
fixed #318 for casperjs too
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBAshton committed May 22, 2016
1 parent 25637d3 commit 8759fb9
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions lib/wraith/javascript/casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var url = casper.cli.get(0),
globalBeforeCaptureJS = casper.cli.get(4),
pathBeforeCaptureJS = casper.cli.get(5),
dimensionsProcessed = 0,
currentDimensions;
currentDimensions = dimensions;

// functions
function requireRelative(file) {
Expand All @@ -23,11 +23,35 @@ function requireRelative(file) {
currentFilePath = fs.absolute(currentFilePath.join('/'));
return require(currentFilePath + '/' + file);
}

function setViewportHeight() {
if (!currentDimensions.viewportHeight) {
currentDimensions.viewportHeight = 1500;
}
}

function snap() {
console.log('Snapping ' + url + ' at: ' + currentDimensions.viewportWidth + 'x' + currentDimensions.viewportHeight);
// dynamic height calculation not possible in the following situations:
// * `resize` mode
// * non-JavaScript mode
var documentHeight = this.evaluate(function () {
return document.body.offsetHeight;
}) || false;

if (!documentHeight) {
documentHeight = 1500;
console.log('Could not dynamically determine document height.');
}

console.log('Snapping ' + url + ' at: ' + currentDimensions.viewportWidth + 'x' + documentHeight);

if (!selector) {
this.capture(image_name);
this.capture(image_name, {
top: 0,
left: 0,
width: currentDimensions.viewportWidth,
height: documentHeight
});
}
else {
this.captureSelector(image_name, selector);
Expand All @@ -36,6 +60,7 @@ function snap() {
dimensionsProcessed++;
if (helper.takingMultipleScreenshots(dimensions) && dimensionsProcessed < dimensions.length) {
currentDimensions = dimensions[dimensionsProcessed];
setViewportHeight();
image_name = helper.replaceImageNameWithDimensions(image_name, currentDimensions);
casper.viewport(currentDimensions.viewportWidth, currentDimensions.viewportHeight);
casper.wait(300, function then () {
Expand All @@ -46,11 +71,11 @@ function snap() {

if (helper.takingMultipleScreenshots(dimensions)) {
currentDimensions = dimensions[0];
setViewportHeight();
image_name = helper.replaceImageNameWithDimensions(image_name, currentDimensions);
}
else {
currentDimensions = dimensions;
}

setViewportHeight();

// Casper can now do its magic
casper.start();
Expand Down

0 comments on commit 8759fb9

Please sign in to comment.