playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] Custom expect message is not displayed in report when using async in fixture

Open michael-yelnikov opened this issue 1 year ago • 2 comments

System info

Source code

import { test, expect } from "./test";

test("has title", async ({ page }) => {
  await page.goto("https://playwright.dev/");
  await expect(page, "Check titlte").toHaveTitle(/Playwright/);
});

test.ts:

import { test as base } from "@playwright/test";

export const test = base.extend<{ allureFixture: void }>({
  allureFixture: [
    async ({}, use) => {
      await test.step("Allure fixture description", async () => {
        // ... 
        await use();
      });
    },
    { auto: true },
  ],
});
export { expect } from "@playwright/test";

Steps to Reproduce:

  1. Create an asynchronous step within a fixture using test.step.
  2. Define a test that includes a custom message in expect.
  3. Execute the test with Allure reporting enabled.

Expected Result: The custom message inside the test should be displayed in the report as an individual step.

Actual Result: The custom message is not displayed in the report.

image

It was happened after: https://github.com/microsoft/playwright/issues/28528

Why need to use asynchronous code in a fixture is a rhetorical question 😄

michael-yelnikov avatar Feb 01 '24 10:02 michael-yelnikov

By the way, “goto” is not displayed also

ekaterinakuchmistova avatar Feb 01 '24 11:02 ekaterinakuchmistova

They are all available under the Before Hooks.

Here is how fixtures work:

  allureFixture: async ({}, use) => {
    // this code runs before test for setup
    await use(); // <-- test runs inside this call
    // this code runs after test for tear down
  }

and the report looks like this: image

You'll see two entries for the allureFixture, one is before the test and another is after.

When you wrap use() with a step:

  allureFixture: [
    async ({}, use) => {
      await test.step("Allure fixture description", async () => {
        await use();
      });
    },

You give reporter an impossible task to show before and after separately, but at the same time to show them under the same step. Playwright falls back to attributing the entire step to where it was called and places it in its entirety to under before hooks.

You probably don't need the step as fixtures get automatic steps generated already as seen on the screenshot. But if you want a synthetic entry you can always do something like this:

    async ({}, use) => {
      expect(true, 'Setting up allure').toBeTruthy();
      await use();
      expect(true, 'Tearing down allure').toBeTruthy();
    },

pavelfeldman avatar Feb 01 '24 17:02 pavelfeldman

Closing as per above

pavelfeldman avatar Feb 06 '24 00:02 pavelfeldman