This thread is trying to answer question "No question provided"
import * as debug from 'debug'; import * as fs from 'fs'; import { test as base } from '@playwright/test';
export const test = base.extend<{ saveLogs: void }>({ saveLogs: [async ({}, use, testInfo) => { // Collecting logs during the test. const logs = []; debug.log = (...args) => logs.push(args.map(String).join('')); debug.enable('myserver');
await use();
// After the test we can check whether the test passed or failed.
if (testInfo.status !== testInfo.expectedStatus) {
// outputPath() API guarantees a unique file name.
const logFile = testInfo.outputPath('logs.txt');
await fs.promises.writeFile(logFile, logs.join('\n'), 'utf8');
testInfo.attachments.push({ name: 'logs', contentType: 'text/plain', path: logFile });
}
}, { auto: true }], }); export { expect } from '@playwright/test';
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].