是否可以在测试之外访问被覆盖的 Playwright 配置?

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

提问人:Danno 提问时间:11/16/2023 更新时间:11/16/2023 访问量:29

问:

我有一个文件,其中包含有关运行测试列表的信息。我需要能够动态生成此文件的路径,具体取决于项目设置。

目前我正在尝试以下操作,但只有在配置文件的全局使用部分设置了值时,它才有效。如果该值来自项目,则该值不可用。

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);
        });
    });
});

我知道我可以使用环境变量,但我宁愿将所有配置保留在配置文件中。

打字稿 作家测试

评论


答: 暂无答案