tm-playwright-framework
Version:
Playwright Cucumber TS framework - The easiest way to learn
61 lines (60 loc) • 2.26 kB
JavaScript
/**
* LOGGER.TS
*
* This TypeScript file contains methods to create Cucumber default logs during execution
*
* @author Sasitharan, Govindharam
* @reviewer Sahoo, AshokKumar
* @version 1.0 - 1st-JUNE-2025
*
* @methods
* - `log`: Method to log the message based on status received
* - `logStatus`: Method to receive the message along with the status to log the message as info or error
*/
import { transports, format } from "winston";
import { fixture } from "tm-playwright-framework/dist/hooks/pageFixture.js";
export const silentErrors = [];
export function options(scenarioName, path) {
return {
transports: [
new transports.File({
filename: path ? `${path}/${scenarioName}.html` : `${process.env.REPORT_PATH}/logs/${scenarioName}.html`,
level: 'info',
format: format.combine(format.timestamp({ format: 'MMM-DD-YYYY HH:mm:ss' }), format.align(), format.printf(info => `<tr><td>${info.level}</td><td>${info.message}</td></tr>`)
// <td>${[info.timestamp]}</td>
)
}),
]
};
}
;
export default class Logger {
/* Method to be executed when an Object instantiated for this class */
constructor() { }
static async logSoftAssertFailure(err) {
const message = err.message;
const stackLines = err.stack
? err.stack.split('\n').slice(1, 10).map(line => line.trim())
: [];
fixture.logger.error(`<font color=red><b>${message}</b></font>`);
fixture.logger.error(`<font color=red><b>${err.stack}</b></font>`);
silentErrors.push({
message,
stack: stackLines,
});
}
// Method to log the message based on status received
async log(status, message) {
if (status.toLowerCase() === 'failed' || status.toLowerCase() === 'false') {
fixture.logger.error(`<font color=red><b>${message}</b></font>`);
}
else {
fixture.logger.info(message);
}
}
// Method to receive the message along with the status to log the message as info or error
static logStatus(status, message) {
const logger = new Logger();
return logger.log(status, message);
}
}