There are many ways, but the easiest way to use global variables. If you do not want to clutter your scripts with global variables (which should not be the same problem as global variables in the browser, because you can have different libraries there), you can use IIFE to reduce the area.
casper.start(url); (function(casper){ var a; casper.then(function(){
Another version of the global is to add these variables to the casper object.
Probably the cleanest solution would be to enclose those blocks that need a variable. You should keep in mind that a synchronous function call cannot appear after asynchronous (these are all wait* and then* functions). The planned steps are performed after the completion of the current stamp:
casper.start(url).then(function(){ var a;
Artjom B.
source share