Rayrun
← Back to Discord Forum

Custom 'testsuite' name in JUnit report with Playwright?

I've been using Playwright for testing and generating JUnit reports for TestRail integration. However, I'm facing an issue with the 'testsuite' name in the JUnit report, as it defaults to the file path which isn't very descriptive. Is there a 'suite' entity or something similar in Playwright to define a custom 'testsuite' name for the JUnit report?

This thread is trying to answer question "Is there a 'suite' entity or something similar in Playwright to define a custom 'testsuite' name for the JUnit report?"

0 replies

Answer

Sure, you can define a custom test suite name for the JUnit report in Playwright. The 'suite' entity in Playwright represents a group of tests. It forms a hierarchy where the root suite has child suites for each TestProject, and each project suite has child suites for each test file in the project.

To customize the test suite name, use the 'title' property of the suite. Here's an example:

const myProjectSuite = new Suite('MyProjectSuite');

You can also create a custom reporter to further customize your reports. Here's a simple custom reporter that logs the title of each test run:

import { Reporter } from '@playwright/test/reporter';
import { Suite } from '@playwright/test';

class MyReporter implements Reporter {
  onTestBegin(test: TestCase) {
    console.log(`Starting test: ${test.title}`);
  }

  onTestEnd(test: TestCase) {
    console.log(`Finished test: ${test.title}`);
  }
}

export default MyReporter;

Then, configure Playwright Test to use your custom reporter in the 'reporter' option of your configuration file (playwright.config.ts):

import { defineConfig } from '@playwright/test';
import MyReporter from './my-reporter';

export default defineConfig({
  reporter: MyReporter,
});

With this setup, your custom reporter will log detailed information about each test run, including the suite name. This way, you can customize your JUnit report as per your requirements.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].