casperJS没有登录到控制台

时间:2012-01-24 15:46:53

标签: javascript phantomjs

学习CasperJS

试图理解为什么以下内容没有在控制台中显示我的结果....

输出:

casperjs testcasper.js 

[info] [幻影]开始...... [info] [幻影]跑步套件:3个步骤

代码:

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();

1 个答案:

答案 0 :(得分:6)

在所有已执行的步骤之后,必须异步调用

casper.exit() ;在你的脚本中,这给出了:

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