How do I create a `metainfo.json` file without executing all tests in @playwright/test?


Generating a metainfo.json File

Unfortunately, there isn't a built-in feature in @playwright/test to generate a metainfo.json file without running all tests. However, you can create a custom script to achieve this.

First, create a TypeScript file, e.g., generateMetainfo.ts, and import the necessary modules:

import { test as baseTest } from '@playwright/test';
import { promises as fs } from 'fs';
import path from 'path';

Next, define a custom test function that wraps the base test function and collects test metadata:

const testMetadata: any[] = [];

const test = baseTest.extend({
  metadataCollector: {
    async init() {},
    async afterEach(testInfo) {
        title: testInfo.title,
        file: testInfo.file,

Now, use the custom test function to define your tests. For example:

test('Visit https://ray.run/', async ({ page }) => {
  await page.goto('https://ray.run/');
  // Your test code here

Finally, add a function to write the collected metadata to a metainfo.json file after all tests have been executed:

test.afterAll(async () => {
  const metainfoPath = path.join(__dirname, 'metainfo.json');
  await fs.writeFile(metainfoPath, JSON.stringify(testMetadata, null, 2));

This script will generate a metainfo.json file containing the metadata of all tests when you run your test suite. Note that this approach still requires running the tests, but you can modify the script to skip test execution and only collect metadata if needed.

For more tips on writing efficient @playwright/test scripts, check out Tips for Writing Efficient Playwright Test Scripts.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

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 luc@ray.run.