This thread is trying to answer question "How to get each test group's title like testInfo.title?"
Related Ask AI answer for "How can I programmatically retrieve the title of each test group in Playwright Test?".
You can use the test.describe()
function in Playwright Test to declare a test group. The title
parameter within the callback of test.describe()
represents the title of the test group. Here's an example:
import { test } from '@playwright/test';
test.describe('Group 1', () => {
// Tests for Group 1
});
test.describe('Group 2', () => {
// Tests for Group 2
});
In this example, "Group 1" and "Group 2" are the titles of the test groups.
To access these titles programmatically, use the suite.titlePath()
method. This method returns an array of titles from the root down to a specific suite (a test group). Here's how you can retrieve each test group's title:
import { suite } from '@playwright/test';
// Get all suites in your project
const allSuites = suite.allSuites();
// Iterate over each suite and retrieve its title path
for (const currentSuite of allSuites) {
const titles = currentSuite.titlePath();
const groupName = titles.join(' > ');
console.log(`Test Group Title: ${groupName}`);
}
In this code, we first get all suites using suite.allSuites()
. Then we iterate over each suite and retrieve its title path using currentSuite.titlePath()
. The titles are joined together with the separator " > " to form the complete test group title. Finally, we log each test group's title to the console.
By following these steps, you can programmatically retrieve each test group's title in Playwright Test.
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].