playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Browser name in testcase name in JUnit reporter

Open creage opened this issue 3 years ago • 4 comments

We run PW tests using Azure DevOps, and there is only one compatible reporter we can use so far, is JUnit.

It works fine, except that it doesn't write the browser name which was used for executing a test, to the <testcase name="">, leading to not very friendly view:

image

This is a single test run in two browsers, but there is no way to know which row was run on which of these two browsers. The only way to learn that, is to download the results XML and investigate it manually.

What we'd like to have, is an option (since not everybody is using Azure DevOps) to prepend a browser name to the name value in testcase node of XML, same as you already do for classname attribute:

<testcase name="151950: Edit configuration: User without CONFIGADM rights" classname="[chromium] › Configuration\151950.ts:5:1 › 151950: Edit configuration: User without CONFIGADM rights" time="5.811">
</testcase>

Alternatively, it could be a placeholder we can use in the test name, like _browser_:

test('[_browser_]: 151950: Edit configuration: User without CONFIGADM rights', async ({
	browser
}) => {
...
});

creage avatar Jun 04 '22 17:06 creage

@creage AzureDevOps actually has a specific format - TRX. We'd be happy to have a built-in reporter for TRX, that should be able to support anything.

Would you be interested in implementing a TRX reporter?

aslushnikov avatar Jun 06 '22 17:06 aslushnikov

https://github.com/microsoft/playwright/issues/11143 We know. But the TRX schema is not available for public AFAIK, thus we are limited by JUnit.

creage avatar Jun 06 '22 17:06 creage

I was able to add the browser name to the test case title in the junit xml report, using a custom reporter..

// customReporter.ts
import { Reporter, TestCase } from '@playwright/test/reporter';

class MyReporter implements Reporter {
  onTestBegin(test: TestCase) {
    test.title += ` [${test.parent.parent!.title}]`
    console.log(`Starting test ${test.title} - ${test.parent.parent!.title}`);
  }
}
export default MyReporter;

Add the reporter to your playwright config..

// playwright.config.ts
reporter: [
    ['./path/to/customReporter.ts'],
    ['junit', { outputFile: 'reports/test-results.xml' }]
  ]

Then the junit xml report will have the browser name at the end of the test title, and will now show when the junit xml is published in an Azure DevOps pipeline

formarfr avatar Oct 18 '22 17:10 formarfr

I was able to add the browser name to the test case title in the junit xml report, using a custom reporter..

// customReporter.ts
import { Reporter, TestCase } from '@playwright/test/reporter';

class MyReporter implements Reporter {
  onTestBegin(test: TestCase) {
    test.title += ` [${test.parent.parent!.title}]`
    console.log(`Starting test ${test.title} - ${test.parent.parent!.title}`);
  }
}
export default MyReporter;

Add the reporter to your playwright config..

// playwright.config.ts
reporter: [
    ['./path/to/customReporter.ts'],
    ['junit', { outputFile: 'reports/test-results.xml' }]
  ]

Then the junit xml report will have the browser name at the end of the test title, and will now show when the junit xml is published in an Azure DevOps pipeline

I wonder if this will work with allure reports

mrrinatino avatar Dec 13 '22 12:12 mrrinatino

I'm in a similar situation where we upload our junit.xml to a tool to track test health over time and having the browser in the testcase name would be extremely helpful

fedorareis avatar Jan 19 '23 00:01 fedorareis

@creage @fedorareis - Are you guys able to append the browser name or project name in the testcase name ? What solution works for this issue ? I also want to upload our junit.xml to a tool to track test health over time.

bhavarthkandoria avatar Jun 01 '23 14:06 bhavarthkandoria

I have the same question: how can I add the browser to the test unit? Is it only with some custom reporter?

apis3445 avatar Oct 18 '23 04:10 apis3445

Folding into https://github.com/microsoft/playwright/issues/23432

mxschmitt avatar Oct 18 '23 17:10 mxschmitt

I have the same question: how can I add the browser to the test unit? Is it only with some custom reporter?

Hey @apis3445, I described a temporary solution here #27665.

EvgenyWas avatar Oct 18 '23 18:10 EvgenyWas