Is there any way to call casperjs methods like capture when function is called from evaluate context ?
Explanation : i want to be able to write js scripts (qunit) that can run both in a "real" browser or in casper.
Sample :
function screenshot()(
//i'm runing in a "real" browser ? Then only console.log
//i'm running in casper ? Then call capser.capture()
I tried this with closure but fails :
var casper = require('casper').create();
casper.start('http://google.fr/');
casper.evaluate(function(o) {
o.capture('/tmp/google.png', {
top: 100,
left: 100,
width: 500,
height: 400
});
}, {o: this});
casper.run()
TypeError: JSON.stringify cannot serialize cyclic structures.
:/modules/webpage.js:249
/Users/macbookpro/js:576 in evaluate
/Users/macbookpro/js/testClosure.js:11
I know there's a way to use use console.log as a message bus but i'm searching for a better solution.
Thanks