0

我正在使用 Playwright.dev 来自动化我们的 UI 测试。目前我面临以下问题:

在一个spec.ts文件中,我有不同的测试套件。这些测试套件应该并行运行,而不是每个测试。我无法将这些测试套件拆分为单独的文件,因为它们是动态创建的。我为什么要运行每个测试套件系列的测试是为了重用现有页面。因为在不完全刷新页面的情况下重用页面要快得多。我将尝试用一些伪代码来解释我的问题:

catalogs.forEach((objectIdsOfCatalog, catalogId) => {
    // each suite could run in parallel because they do not
    // depend on each other
    test.describe('Test catalog "' + catalogId + '"', () => {
        let newVersion: PageObject;
        let actualVersion: PageObject;

        test.beforeAll(async ({browser}) => {
            console.log('New page for', catalogId);
            const {actualUrl, newUrl} = getConfig();
            const context = await browser.newContext();
            actualVersion = new PageObject(await context.newPage(), actualUrl);
            newVersion = new PageObject(await context.newPage(), newUrl);
        });

        test.afterAll(async () => {
            console.log('Close page for', catalogId);
            actualVersion.close();
            newVersion.close();
            actualVersion = null;
            newVersion = null;
        });
        // those tests should ran serial because it's faster
        // if we just navigate on the existing page due to the
        // client side caching of the web app
        for (const objectId of objectIdsOfCatalog) {
            test('Testing "' + objectId + '"', async () => {
            });
        }
    });
});

有什么方法可以在 Playwright 中实现以下行为,还是我必须重新考虑我的方法?

4

1 回答 1

0

我不知道多个 test.describe.serial 块是否可以嵌套在 test.describe.parallel 中(如果可行),但也许值得一试。

另一种选择可能是不生成真正的测试,而只是在 test.describe.parallel 块内的测试中生成步骤(test.step)。

目录从何而来?也许您可以在 playwright.config.ts 中生成项目,而不是生成描述块?我认为项目默认并行运行。但不知道如果数据来自某个异步源,这种方法是否可行。

于 2021-11-24T19:57:01.270 回答