Skip to content

Commit

Permalink
fix #345
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBAshton committed Dec 3, 2015
1 parent 1f36fe9 commit 2478ed3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions lib/wraith/javascript/_phantom__common.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = function (config) {
currentDimensions = dimensions;
}

page.viewportSize = { width: currentDimensions.viewportWidth, height: currentDimensions.viewportHeight};
page.settings = { loadImages: true, javascriptEnabled: javascriptEnabled };

// If you want to use additional phantomjs commands, place them here
Expand All @@ -58,18 +57,27 @@ module.exports = function (config) {
});

function runSetupJavaScriptThenCaptureImage() {
resize();
if (globalBeforeCaptureJS) {
require(globalBeforeCaptureJS)(page);
}
if (pathBeforeCaptureJS) {
require(pathBeforeCaptureJS)(page);
}
captureImage();
resizeAndCaptureImage();
}

function captureImage() {
function resize() {
page.viewportSize = { width: currentDimensions.viewportWidth, height: currentDimensions.viewportHeight};
}

function resizeAndCaptureImage() {
console.log('Snapping ' + url + ' at: ' + currentDimensions.viewportWidth + 'x' + currentDimensions.viewportHeight);
resize();
setTimeout(captureImage, 1000); // give page time to re-render properly
}

function captureImage() {
page.clipRect = {
top: 0,
left: 0,
Expand All @@ -82,7 +90,7 @@ module.exports = function (config) {
if (helper.takingMultipleScreenshots(dimensions) && dimensionsProcessed < dimensions.length) {
currentDimensions = dimensions[dimensionsProcessed];
image_name = helper.replaceImageNameWithDimensions(image_name, currentDimensions);
setTimeout(captureImage, 1000);
setTimeout(resizeAndCaptureImage, 1000);
}
else {
// prevent CI from failing from 'Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL' errors
Expand Down
2 changes: 1 addition & 1 deletion lib/wraith/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wraith
VERSION = "3.0.3"
VERSION = "3.0.4"
end

0 comments on commit 2478ed3

Please sign in to comment.