Skip to content

[BUG] Incorrect serialization failure message in Junit reporter #12944

Closed

Description

Context:

  • Playwright Version: [1.20.0]
  • Operating System: [Windows 10]
  • Node.js version: [v14.17.5]
  • Browser: [All]

Code Snippet

Hello everyone 🎭✋🏻! I found incorrect junit reporter serialization work;
when the test fails I expect the "failure message" field in the xml file to contain the error text, but it contains the test header:

<failure message="example.spec.ts:5:3 Check equal" type="FAILURE">

test code:

test.describe('Example', () => {

  test('Check equal', async () => {
    throw new Error('Error message');
  });
});

how it looks in json reporter:

"error": {
  "message": "Error message",
  "stack": "Error: Error message\n    at C:\\Users\\username\\Desktop\\issue\\new-project\\tests\\example.spec.ts:6:11"
},

I prepared a repository with npm scripts:

npm run testJson - for run with json reporter
npm run testJunit - for run with junit reporter

I hope this makes your job easier, thanks for Playwright!❤

Activity

  1. dgozman commented on Mar 22, 2022

    @dgozman
    Collaborator

    MoMentuMRace (@Gornostalev) The actual failure should be a text node child of the <failure> tag:

    <failure message="example.spec.ts:5:3 Check equal" type="FAILURE">
      example.test.js:5:3 › Check equal =====================================================
    
        Error: Error message
        ......
    </failure>

    Is that text missing for you?

  2. Gornostalev commented on Mar 22, 2022

    @Gornostalev
    Author

    Dmitry Gozman (@dgozman), i know about this, but attribute message parsed for results in pipeline azure devops, and on screenshot field "Error message" not contain error message, it just a test title:
    image

  3. dgozman commented on Mar 22, 2022

    @dgozman
    Collaborator

    Thank you for the screenshot, this makes sense.

    Ideally, we would make the following improvements:

    • Use <error> element for thrown errors, and <failure> element for expect failures.
    • For errors:
      • Put error.name in type="" attribute for errors.
      • Put error message in message="" attribute.
    • For failures (expects):
      • Put expect.toBe in type="" attribute.
      • Put (possibly custom) expect message in message="" attribute.
  4. removed their assignment
    on May 30, 2022
  5. added a commit that references this issue on Oct 16, 2025
    5f9b135
  6. added a commit that references this issue on Feb 22, 2026
    78ccd46
  7. vazidmansuri005 commented on Feb 22, 2026

    @vazidmansuri005
    Contributor

    Hey Dmitry Gozman (@dgozman) 👋

    I've opened a PR to fix this: #39350

    Following your guidance from the comments above:

    • Assertion failures (expect) → <failure> with matcher name in type="" (e.g., expect.toBe) and actual error message in message=""
    • Thrown errors → <error> with error class in type="" (e.g., Error, TypeError) and error message in message=""
    • errors="" counter now reflects actual thrown error count instead of hardcoded 0

    This also addresses #39193 (distinguishing <error> from <failure> elements).

    Happy to address any feedback!

  8. added 2 commits that reference this issue on Feb 23, 2026
    7c79e2a
    694e90e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions