我正在使用 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 中实现以下行为,还是我必须重新考虑我的方法?