Skip to content

Find out why a test failed

You’ll investigate a checkout page that should confirm a successful payment but still tells the customer it’s pending. You’ll use TestPerch to find the mismatch and check a fix.

Start with a suite that can send a run to TestPerch. If you already have a failed run you want to investigate, go straight to Find the failed step.

Add order-status.spec.ts alongside your existing tests. This example supplies its own page and asks Playwright to keep a screenshot and trace on failure.

import { expect, test } from "@playwright/test";
test.use({ screenshot: "only-on-failure", trace: "retain-on-failure" });
test("checkout shows the payment status", async ({ page }) => {
await page.setContent('<p role="status">Payment pending</p>');
await expect(page.getByRole("status")).toHaveText("Payment received");
});

With your reporter key set, run the example.

Terminal window
pnpm exec playwright test order-status.spec.ts
  1. In your TestPerch project, open Runs and select the run you just recorded.
  2. Filter the results to Failed and open checkout shows the payment status.
  3. Choose the failed Attempt. Under Steps, find Failed step. The assertion expected Payment received and found Payment pending.
  4. Under Attachments, open the screenshot to see the text on the page. For a closer look, choose Open in trace viewer and select the assertion to inspect the page at that moment.

For a failure in your own suite, Copy debug prompt gives you the failure details to paste into your coding assistant. A useful first question is “What did the test expect, and what did the page actually show?”

In the sample page, change the text inside <p role="status"> to Payment received. Run the same command again. Open the new run and find the same test under Successful. You now have two results to compare, one showing the mismatch and one confirming the fix.