Can you access the overridden Playwright configuration outside of a test?

154 Views Asked by At

I have a file containing information on running a list of tests. I need to be able to dynamically generate the path for this file, depending on a project setting.

Currently I'm attempting the following, but it only works if values are set in the global use section of the config file. If the value is coming from the project, that value is not available.

import config from '../../playwright.config';

test.describe('JSON Based Tests', () => {

    let tests: TestData[] = [];

    // *** how can I get the overriden project "use" section here ***
    let siteType = config.use?.siteType;
    console.log(JSON.stringify(config.use));

    if (!siteType) {
        throw new Error('siteType was not specified.');
    }

    let filePath = path.join(__dirname, `../../data/${siteType}/testData.json`);
    let fileJson = fs.readFileSync(filePath, "utf-8");

    tests = JSON.parse(fileJson);


    tests.forEach((testData) => {
        if (testData.skip)
            return;

        // validations, dataInfo and siteType are all injected via the configuration extension mechanism
        test(testData.name, async ({ validations, dataInfo, siteType }) => {
            await validations.runQuery(testData, dataInfo, siteType);
        });
    });
});

I know I can use environment variables, but I'd rather keep all of the configuration inside the configuration file.

0

There are 0 best solutions below