playwright
playwright copied to clipboard
[BUG] Custom expect message is not displayed in report when using async in fixture
System info
- Playwright Version: v1.41.1
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:
- Create an asynchronous step within a fixture using test.step.
- Define a test that includes a custom message in expect.
- 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.
It was happened after: https://github.com/microsoft/playwright/issues/28528
Why need to use asynchronous code in a fixture is a rhetorical question 😄
By the way, “goto” is not displayed also
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:
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();
},
Closing as per above