【发布时间】: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