12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import fs from 'node:fs';
-
- /**
- * A prefix to use for all messages we add to the console log.
- */
- export const LOG_PREFIX = '[MeetTest] ';
-
- /**
- * Initialize logger for a driver.
- *
- * @param {WebdriverIO.Browser} driver - The driver.
- * @param {string} name - The name of the participant.
- * @param {string} folder - The folder to save the file.
- * @returns {void}
- */
- export function initLogger(driver: WebdriverIO.Browser, name: string, folder: string) {
- // @ts-ignore
- driver.logFile = `${folder}/${name}.log`;
- driver.sessionSubscribe({ events: [ 'log.entryAdded' ] });
-
- driver.on('log.entryAdded', (entry: any) => {
- try {
- // @ts-ignore
- fs.appendFileSync(driver.logFile, `${entry.text}\n`);
- } catch (err) {
- console.error(err);
- }
- });
- }
-
- /**
- * Returns the content of the log file.
- *
- * @param {WebdriverIO.Browser} driver - The driver which log file is requested.
- * @returns {string} The content of the log file.
- */
- export function getLogs(driver: WebdriverIO.Browser) {
- // @ts-ignore
- if (!driver.logFile) {
- return;
- }
-
- // @ts-ignore
- return fs.readFileSync(driver.logFile, 'utf8');
- }
-
- /**
- * Logs a message in the logfile.
- *
- * @param {WebdriverIO.Browser} driver - The participant in which log file to write.
- * @param {string} message - The message to add.
- * @returns {void}
- */
- export function logInfo(driver: WebdriverIO.Browser, message: string) {
- // @ts-ignore
- if (!driver.logFile) {
- return;
- }
-
- try {
- // @ts-ignore
- fs.appendFileSync(driver.logFile, `${new Date().toISOString()} ${LOG_PREFIX} ${message}\n`);
- } catch (err) {
- console.error(err);
- }
- }
|