reportingplaywright

Adding expect value to Playwright html report


I want to know how I can include the values I expect on in my Playwright html report.

It would be useful to see the URL and title I am expecting on to appear in the report.

expect.toHaveURL— ../src/objects/pages/pageObject.ts:18 expect.toHaveTitle— ../src/objects/pages/pageObject.ts:26

Snippet from report


Solution

  • You can add a custom expect message like this:

    import { expect, test } from "@playwright/test";
    
    test("Test", async ({ page }) => {
      await page.goto("https://playwright.dev/");
      await page.getByRole("link", { name: "Get started" }).click();
    
      // As a second parameter in expect:
      await expect(page, "Expect url: https://playwright.dev/docs/intro").toHaveURL(
        "https://playwright.dev/docs/intro"
      );
    });
    

    Will show like this in the html report:

    Screenshot of html report