【问题标题】:Winston Logger not working outside playwright test listeners/reportersWinston Logger 不能在剧作家测试听众/记者之外工作
【发布时间】:2021-10-23 13:59:59
【问题描述】:

背景:我已经用 POM 设计模式和 playwright 使用 typescript 语言实现了自动化框架。

我已经实现了 winston 记录器来为自动化框架创建我的自定义记录器。 下面是记录器的代码sn-p

const logger = winston.createLogger({
    exitOnError:false,
    silent:false,
    levels : Levels,
        transports: [
            new winston.transports.File({
                filename: 'debug'+'.log',     
                format: combine(
                    format.colorize(),
                    splat(),
                    timestamp(),
                    customFormat
              )        
            }),
            new winston.transports.Console({
                format: combine(
                    format.colorize(),
                    splat(),
                    timestamp(),
                    customFormat
                )}
            ),
        ]
    });

我也实现了测试侦听器,并利用上面的记录器在测试运行期间在控制台和文件中记录信息/错误。

    onBegin(config, suite) {
        logger.info(`Starting the run with ${suite.allTests().length} tests`);
      } 

但记录器仅适用于测试侦听器。

如果我在 Page 类或测试函数中使用 logger.info()console.log() - 它不会在控制台或文件中记录任何内容。关于如何修复它的任何建议?

【问题讨论】:

  • 我个人不知道自动化,但是对于您的 Page 类或 Test 函数的情况,确定记录器已实例化(可能在创建行上设置断点)?
  • 感谢您的建议。帮助确定问题

标签: typescript logging automation winston playwright


【解决方案1】:

已发现问题:记录器未在页面类中实例化。

修复如下问题:

  1. 通过在记录器定义文件的末尾添加以下代码,将记录器导出为默认值:

    export default logger;

  2. 在页面中导入并使用了logger。

【讨论】:

    猜你喜欢
    • 2018-08-06
    • 1970-01-01
    • 2021-03-08
    • 2021-01-28
    • 2021-05-26
    • 2021-08-14
    • 1970-01-01
    • 2022-09-24
    • 2022-06-24
    相关资源
    最近更新 更多