ReferenceConfiguration

Custom reporters

Use your own Playwright custom reporters with Endform, when they run, the extra properties Endform adds to results, and how quarantined results are reported.

Endform supports Playwright's custom reporters. Configure them in your Playwright config as usual. They implement the Playwright reporter interface and can read the extra properties Endform adds:

my-reporter.ts
import type {
  FullConfig,
  FullResult,
  Reporter,
  Suite,
  TestCase,
  TestResult,
} from "@playwright/test/reporter";

class MyCustomReporter implements Reporter {
  onBegin(config: FullConfig, suite: Suite) {
    console.log("Endform Report URL:", config.metadata.endformReportURL);
    console.log(`Running ${suite.allTests().length} tests`);
  }

  onTestBegin(test: TestCase) {
    console.log(`Starting test: ${test.title}`);
  }

  onTestEnd(test: TestCase, result: TestResult) {
    console.log(`Finished test: ${test.title}`);
    const endformTraceUrl = result.annotations.find(
      (annotation) => annotation.type === "endformTestAttemptTraceURL",
    )?.description;
    if (endformTraceUrl) {
      console.log(`Endform trace URL: ${endformTraceUrl}`);
    }

    const endformOtelTraceUrl = result.annotations.find(
      (annotation) => annotation.type === "endformTestAttemptOtelTraceURL",
    )?.description;
    if (endformOtelTraceUrl) {
      console.log(`Endform OpenTelemetry trace URL: ${endformOtelTraceUrl}`);
    }
  }

  onEnd(result: FullResult) {
    console.log(`Test suite finished with status: ${result.status}`);
  }
}

export default MyCustomReporter;

When custom reporters run

Custom reporters run after all tests have finished, not live while the tests run on the remote runners. This follows how Playwright runs sharded suites.

Each test runs on a remote runner, which sends a blob report back to the machine that started the run. When every test has finished, Endform runs Playwright's merge-reports command, and that is when your custom reporters run.

Properties Endform adds

Endform report URL

In the onBegin hook, config.metadata.endformReportURL links to the suite run in the Endform dashboard:

onBegin(config: FullConfig, suite: Suite) {
  console.log("Endform Report URL:", config.metadata.endformReportURL);
  // https://endform.dev/app/org/xyz/suite-run?suite_run_id=...
}

Endform test attempt URL

In the onTestEnd hook, an annotation of type endformTestAttemptTraceURL links to the trace of the test attempt, when one was created:

onTestEnd(test: TestCase, result: TestResult) {
  const endformTraceUrl = result.annotations.find(
    (annotation) => annotation.type === "endformTestAttemptTraceURL",
  )?.description;
  if (endformTraceUrl) {
    console.log(`Endform trace URL: ${endformTraceUrl}`);
    // https://endform.dev/app/org/xyz...
  }
}

Endform OpenTelemetry trace URL

When the remote runner produced a Playwright OpenTelemetry trace for a test attempt, an annotation of type endformTestAttemptOtelTraceURL links to it. Endform detects the trace from the playwrightOpentelemetryTraceId annotation that the Playwright OpenTelemetry reporter, playwright-opentelemetry/reporter, adds:

onTestEnd(test: TestCase, result: TestResult) {
  const endformOtelTraceUrl = result.annotations.find(
    (annotation) => annotation.type === "endformTestAttemptOtelTraceURL",
  )?.description;
  if (endformOtelTraceUrl) {
    console.log(`Endform OpenTelemetry trace URL: ${endformOtelTraceUrl}`);
    // https://endform.dev/app/org/xyz...
  }
}

Quarantined results

Quarantine rules let selected tests keep running without their failures failing the suite. The Endform dashboard and analytics keep the actual outcomes, but the merged blob reports that Playwright reporters read show a passing result for a quarantined attempt whose original status is passed, failed or timedOut.

For those attempts, the status and expected status are passed and the errors are cleared. An HTML, JUnit or custom reporter can therefore show a pass where the Endform dashboard shows a quarantined failure. Skipped and interrupted attempts, and attempts that did not run, are not turned into passes.

The original result is kept in two places:

  • An endform-quarantined annotation names the quarantine rule and the original status.
  • An application/json attachment named endform-quarantined-original-result holds quarantineRuleId, status, expectedStatus, errors and annotations from the original attempt.

If your reporter needs the original outcome, read the attachment instead of result.status. The attachment has either an inline body or a file path:

quarantine-reporter.ts
import { readFileSync } from "node:fs";
import type { Reporter, TestCase, TestResult } from "@playwright/test/reporter";

export default class QuarantineReporter implements Reporter {
  onTestEnd(test: TestCase, result: TestResult) {
    const attachment = result.attachments.find(
      (item) => item.name === "endform-quarantined-original-result",
    );
    if (!attachment) return;

    const body =
      attachment.body ??
      (attachment.path ? readFileSync(attachment.path) : null);
    if (!body) return;

    const original = JSON.parse(body.toString("utf8"));
    console.log(`${test.title}: ${original.status} (quarantined)`);
    console.log("Quarantine rule:", original.quarantineRuleId);
  }
}

Endform's own terminal reporter reads these to show the original outcomes with quarantine labels and counts.

Last updated