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] Custom expect message is not displayed in report when using async in fixture #29289

Closed michael-yelnikov closed 8 months ago

michael-yelnikov commented 8 months ago

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 😄

ekaterinakuchmistova commented 8 months ago

By the way, “goto” is not displayed also

pavelfeldman commented 8 months ago

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 commented 8 months ago

Closing as per above