allure-js icon indicating copy to clipboard operation
allure-js copied to clipboard

[allure-playwright] Expect message is displayed twice in the report when using a custom error message.

Open sam-viz opened this issue 2 years ago • 2 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

I have encountered an issue using the following packages version: "@playwright/test": "1.39.0" "allure-playwright": "2.9.2"

The issue: When using expect with a custom error message, there are two lines displayed in the Allure report. Snippet code to reproduce: Playwright configuration:

reporter: [
    ['allure-playwright',
      {
        detail: true,
        outputFolder: 'allure-results',
        suiteTitle: false,
      },
    ]
]

Test code to reproduce:

import test, { expect } from '@playwright/test';

test.describe('Test scenario', async () => {
  test('Testing scenario', async ({ page }) => {
    await page.goto('https://www.google.com');
    await expect(page, 'User should land on homepage').toHaveURL('/');
  });
});

The report Screenshot 2023-10-31 at 18 34 52

As you can see, there are two lines added in the report. What's confusing is that's one is marked as passed.

After some investigation, i realized there were two step objects. One with expect type and the other was a 'pw:api' type.

Today I used patch-package to patch [email protected] for the project I'm working on. Here is the diff that solved my problem:

diff --git a/node_modules/allure-playwright/dist/index.js b/node_modules/allure-playwright/dist/index.js
index 008957d..7f7a26d 100644
--- a/node_modules/allure-playwright/dist/index.js
+++ b/node_modules/allure-playwright/dist/index.js
@@ -83,6 +83,16 @@ class AllureReporter {
         if (!allureTest) {
             return;
         }
+
+        if(step.title && step.category ===  'pw:api' && _result.steps.find(
+            stepResult => stepResult.category === 'expect' 
+            && step.title.includes(stepResult.title)
+            && step.location.line === stepResult.location.line
+            && step.location.column === stepResult.location.column
+        )){
+            return;
+        }
+        
         if (!this.options.detail && step.category !== "test.step") {
             return;
         }

This is my first time contributing to this repository, I would love to have guidance as to how to fix it more properly.

This issue body was partially generated by patch-package.

sam-viz avatar Oct 31 '23 17:10 sam-viz

We also have this problem

gayvoronskaya avatar Dec 06 '23 10:12 gayvoronskaya

Hey, @sam-viz! Feel free to open PR with the changes you proposed in above. Additionally, it would be great if you provide tests for the changes as proof of work. Then just ask me to review when the PR is ready.

epszaw avatar Dec 06 '23 11:12 epszaw

Works as expected using [email protected] and [email protected]

Screenshot 2024-07-01 at 17 51 27

baev avatar Jul 01 '24 16:07 baev