我目前正在为一个 web 应用程序进行 40 多个测试(它们可能需要 20 多分钟并且不幸会增长),并且正在考虑运行多个浏览器以便并行运行测试。
我目前正在尝试使用puppeter-cluster但没有运气(看不到多个浏览器实例并且断言总是通过)
我已经尝试过,但这似乎是实现此类事情的最接近的方式:
import {Page} from 'puppeteer';
import {Cluster} from 'puppeteer-cluster';
let cluster: Cluster;
describe('Pools', () => {
beforeAll(async () => {
cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 3,
});
});
const task1 = async (page:Page) => {
await page.goto('http://www.wikipedia.org');
const pageTitle = await page.evaluate(() => document.title);
return await expect(pageTitle).toMatch('asdasdasdasdasdadasdasdasdasdadafasfasdasdasdasdasdasdassdadasdadas');
};
describe('Testing', () => {
it('test1', async () => {
await cluster.queue(task1);
});
it('test2', async () => {
await cluster.queue(task1);
});
it('test3', async () => {
await cluster.queue(task1);
});
it('test4', async () => {
await cluster.queue(task1);
});
});
});
玩笑木偶配置:
module.exports = {
launch: {
headless: false, // Use false since hardware acceleration is required for gameplay
ignoreHTTPSErrors: true, // For dev environment testing
defaultViewport: null,
args: [
'--window-size=1920,1040', // Make the site desktop (changing will impact some tests)
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process',
'--mute-audio'
]
},
exitOnPageError: false,
}
PS:不幸的是,我需要将无头模式设置为 false(用于硬件加速)