I have a function called clickMore
:
function clickMore(max, i){
i = i || 0;
if ((max == null || i < max) && this.visible(moreButton)) { // synchronous
// asynchronous steps...
this.thenClick(moreButton); // sometimes the click is not properly dispatched
this.echo('click');
this.waitUntilVisible(loadingButton);
this.waitUntilVisible(moreButton, null, function onTimeout(){
// only placeholder so that the script doesn't "die" here if the end is reached
});
this.then(function(){
//this.capture("business_"+i+".png"); //captures a screenshot of the page
clickMore.call(this, max, i+1); // recursion
});
}
}
I would like to call that function from spooky here:
spooky.then(function(){
clickMore.call(spooky);
})
I've looked through the Spooky docs, and know that I'll probably need to use a function tuple, but not sure how to implement. How can I go about doing this?
UPDATE:
Tried using a function tuple from the SpookyJS documentation with no luck:
spooky.then([{
clickMore: clickMore
}, function(){
clickMore.call(spooky);
}]);
Functions passed into spooky.then
will execute in the Casper/PhantomJS JavaScript environment. They do not have access to Spooky's Node.js JS environment.
spooky.then([{
clickMore: clickMore
}, function(){
clickMore.call(spooky); // <- spooky is not defined here
}]);
Please have another look at what the Introduction wiki page says about JavaScript Environments and the fact that they are isolated.