Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add target url as parameter to beforeCaptureJS #464

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/wraith/javascript/casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ casper.viewport(currentDimensions.viewportWidth, currentDimensions.viewportHeigh
casper.then(function() {
var self = this;
if (globalBeforeCaptureJS && pathBeforeCaptureJS) {
require(globalBeforeCaptureJS)(self, function thenExecuteOtherBeforeCaptureFile() {
require(pathBeforeCaptureJS)(self, captureImage);
});
var thenExecuteOtherBeforeCaptureFile = function() {
require(pathBeforeCaptureJS)(self, captureImage, url);
};
require(globalBeforeCaptureJS)(self, thenExecuteOtherBeforeCaptureFile, url);
}
else if (globalBeforeCaptureJS) {
require(globalBeforeCaptureJS)(self, captureImage);
require(globalBeforeCaptureJS)(self, captureImage, url);
}
else if (pathBeforeCaptureJS) {
require(pathBeforeCaptureJS)(self, captureImage);
require(pathBeforeCaptureJS)(self, captureImage, url);
}
else {
captureImage();
Expand Down
9 changes: 5 additions & 4 deletions lib/wraith/javascript/phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ function markPageAsLoaded() {
function runSetupJavaScriptThen(callback) {
setupJavaScriptRan = true;
if (globalBeforeCaptureJS && pathBeforeCaptureJS) {
require(globalBeforeCaptureJS)(page, function thenExecuteOtherBeforeCaptureFile() {
var thenExecuteOtherBeforeCaptureFile = function () {
require(pathBeforeCaptureJS)(page, callback);
});
};
require(globalBeforeCaptureJS)(page, thenExecuteOtherBeforeCaptureFile, url);
}
else if (globalBeforeCaptureJS) {
require(globalBeforeCaptureJS)(page, callback);
require(globalBeforeCaptureJS)(page, callback, url);
}
else if (pathBeforeCaptureJS) {
require(pathBeforeCaptureJS)(page, callback);
require(pathBeforeCaptureJS)(page, callback, url);
}
else {
callback();
Expand Down
4 changes: 2 additions & 2 deletions templates/javascript/cookies_and_headers--casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (casper, ready) {
module.exports = function (casper, ready, url) {
// reload page with headers set
casper.open(casper.page.url, {
method: 'get',
Expand All @@ -13,4 +13,4 @@ module.exports = function (casper, ready) {
casper.then(function () {
setTimeout(ready, 1000);
});
}
}
2 changes: 1 addition & 1 deletion templates/javascript/cookies_and_headers--phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (phantom, ready) {
module.exports = function (phantom, ready, url) {

page.customHeaders = {
'SOME-HEADER': 'fish'
Expand Down
4 changes: 2 additions & 2 deletions templates/javascript/disable_javascript--casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (casper, ready) {
module.exports = function (casper, ready, url) {
// disable JavaScript
casper.options.pageSettings.javascriptEnabled = false;

// reload the page without JS enabled
casper.thenOpen(casper.page.url);
}
}
4 changes: 2 additions & 2 deletions templates/javascript/disable_javascript--phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (phantom, ready) {
module.exports = function (phantom, ready, url) {
// disable JavaScript
phantom.settings.javascriptEnabled = false;

// reload the page without JS enabled
phantom.open(phantom.url, function () {
setTimeout(ready, 5000);
});
}
}
4 changes: 2 additions & 2 deletions templates/javascript/interact--casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (casper, ready) {
module.exports = function (casper, ready, url) {
// test interaction on the page
casper.wait(2000, function() {
casper.click('.ns-panel__hotspot--2');
ready();
});
}
}
4 changes: 2 additions & 2 deletions templates/javascript/interact--phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (phantom, ready) {
module.exports = function (phantom, ready, url) {

// test interaction on the page
phantom.evaluate(function(){
Expand All @@ -14,4 +14,4 @@ module.exports = function (phantom, ready) {
});

ready();
}
}
4 changes: 2 additions & 2 deletions templates/javascript/wait--casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (casper, ready) {
module.exports = function (casper, ready, url) {
// make Wraith wait a bit longer before taking the screenshot
casper.wait(2000, ready); // you MUST call the ready() callback for Wraith to continue
}
}
4 changes: 2 additions & 2 deletions templates/javascript/wait--phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This is an example module provided by Wraith.
// Feel free to amend for your own requirements.
// ######################################################
module.exports = function (phantom, ready) {
module.exports = function (phantom, ready, url) {
// make Wraith wait a bit longer before taking the screenshot
setTimeout(ready, 2000); // you MUST call the ready() callback for Wraith to continue
}
}