microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.39k stars 3.63k forks source link

[BUG] Multiple Reporters Not Working Correctly #28718

Closed cod3rLP closed 10 months ago

cod3rLP commented 10 months ago

System info

Source code

playwright.config.ts file snippet:

const config: PlaywrightTestConfig = {
  reporter: [['html'], ['./graphite-reporter.ts']],
  };

graphite-reporter.ts file:

import net from 'net';
class CustomReporter implements Reporter {
  private socket: net.Socket;
  private graphiteHost = ‘graphite URL goes here';
  private graphitePort = 'port number goes here';
  private metricList: string[] = [];
  constructor() {
    this.socket = net.createConnection(this.graphitePort, this.graphiteHost);
  }
  onTestEnd(test: TestCase, result: TestResult) {
    const metricName = `hosted-graphite-key-goes-here.playwright.${test.title}.${result.status}`;
    const metricValue = 1;
    const timestamp = Math.floor(Date.now() / 1000);
    this.metricList.push(`${metricName} ${metricValue} ${timestamp}`);
  }
  onEnd() {
    this.metricList.forEach((metric) => {
      this.sendMetric(metric);
    });
    // Close the connection
    this.socket.end();
  }
  private sendMetric(metric: string) {
    this.socket.write(`${metric}\n`);
  }
}
export default CustomReporter;

Steps

Expected

Actual

If it's running in Bitbucket Pipelines, normally using reporter: 'html', as the only reporter will give us details about the test results. Listing both reporters omits the details and looks like this, which is not helpful for anyone seeing why their build failed image

cod3rLP commented 10 months ago

This may actually be the same issue I'm describing. I will try the suggested 'fixes'.

yury-s commented 10 months ago

Please try that. If it doesn't work, please provide a self-contained minimal repro that we could run locally. I tried with the reporter you mentioned above, but I could still see the same output in the console as before.

cod3rLP commented 10 months ago
printsToStdio() {
    return false;
  }

this worked. thank you!