← Back to Discord Forum

automatic fixture

testera_77863posted in #help-playwright
Open in Discord

as per documentation this one - fixture that automatically attaches debug logs when the test fails - why this one shows empty log.txt file in html reporter. am i missing something in test file?

This thread is trying to answer question "No question provided"

4 replies

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';


anyone available for help?

It's an example and debug.enable('myserver'); does not work in your application because it probably does not understand what 'mysever' is or what is debug.

You need to adjust log collection based on your use case and application you're testing.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.