繁体   English   中英

CasperJS中的casper.echo和console.log之间的区别

[英]Difference between casper.echo and console.log in CasperJS

casper.echoconsole.log之间有什么区别吗?

casper.echo('Testing');

console.log('Testing');

它们都在控制台中记录内容。

在最基本的形式中,它们是等价的。

但是有一些区别:

  • (仅适用于PhantomJS)将多个对象传递到console.log()console.log("s", 1, obj)实际上等同于console.log("s" + " " + 1 + " " + obj) 当您在SlimerJS中尝试此操作时,它将只打印第一个参数而忘记其他参数。

  • casper.echo()能够为您提供的输入着色。 签名是:

     Casper.prototype.echo = function echo(text, style, pad) { ... }; 

    这主要用于内部输出着色,如错误和测试工具。 仅当终端默认支持着色时,才可以使用这些颜色

     var styles = { 'ERROR': { bg: 'red', fg: 'white', bold: true }, 'INFO': { fg: 'green', bold: true }, 'TRACE': { fg: 'green', bold: true }, 'PARAMETER': { fg: 'cyan' }, 'COMMENT': { fg: 'yellow' }, 'WARNING': { fg: 'red', bold: true }, 'GREEN_BAR': { fg: 'white', bg: 'green', bold: true }, 'RED_BAR': { fg: 'white', bg: 'red', bold: true }, 'INFO_BAR': { bg: 'cyan', fg: 'white', bold: true }, 'WARN_BAR': { bg: 'yellow', fg: 'white', bold: true }, 'SKIP': { fg: 'magenta', bold: true }, 'SKIP_BAR': { bg: 'magenta', fg: 'white', bold: true } }; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM