1

I at testing some stuff with casperjs, and I am having troubles debugging simple things, I want to run a console.log inside evaluate, read some examples but still can't get it working. This is my test code:

var casper = require("casper").create();
var system = require('system');
var url = casper.cli.get(0);

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});

casper.onConsoleMessage = function(msg) {
    system.stderr.writeLine('console: ' + msg);
};

casper.start(url, function () {
    this.evaluate(function() { console.log('test'); });
});

casper.run(function() {
    console.log('done');
    this.exit();
});

I do get the "done" printed, but never the "test", what am I doing wrong?

Mark
  • 577
  • 1
  • 7
  • 29
  • I've closed your question as duplicate. The duplicate target question is strange, but it's answers perfectly fit your question. – Artjom B. Feb 26 '16 at 10:08
  • @ArtjomB. I've searched on plenty of questions and couldn't find that one, all i found where answers for phantomjs, someone should edit that question title. – Mark Feb 26 '16 at 19:19

2 Answers2

0

Just found the solution, I was using the method for phantomjs, I had to use

casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);
})

instead of onConsoleMessage

Mark
  • 577
  • 1
  • 7
  • 29
0

You can try the below solution as well

//Code to display Console errors
casper.on('remote.message', function (msg) {
     console.log('remote message caught: ' + msg);
 });

//Code to display errors from the page
 casper.on('page.error', function (msg, trace) {
     console.log('Error: ' + msg, 'ERROR');
 });
Prateek.Naik
  • 556
  • 4
  • 18