Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

casperJS not logging to console

Learning CasperJS

Trying to understand why the following is not displaying my results in the console....

output:

casperjs testcasper.js 

[info] [phantom] Starting... [info] [phantom] Running suite: 3 steps

code:

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


casper.start(url, function() {
    this.debugPage();
    this.echo("Test echo.");
    this.fill('form#LogonForm', {
        'username': username,
        'password': password,
        }, true);
});

casper.then(function() {
    casper.echo("I'm loaded.");
});

casper.run(function() {
    console.log(this.getCurrentUrl(),'info'); 
});

//casper.log('this is a debug message', 'debug');
//casper.log('and an informative one', 'info');
//casper.log('and a warning', 'warning');
//casper.log('and an error', 'error');

casper.exit();
like image 356
Cmag Avatar asked Jan 24 '12 15:01

Cmag


1 Answers

casper.exit() must be called asynchronously after all the steps having been executed; in your script, this gives:

casper.run(function() {
    console.log(this.getCurrentUrl(),'info'); 
    this.exit();
});
like image 159
NiKo Avatar answered Sep 23 '22 09:09

NiKo