3
我正在使用Chrome puppeteer库直接运行浏览器集成测试。我现在在单个文件中编写了一些测试。有没有办法平行运行它们?达到此目的的最佳方法是什么?如何启用puppeteer并行测试?
我正在使用Chrome puppeteer库直接运行浏览器集成测试。我现在在单个文件中编写了一些测试。有没有办法平行运行它们?达到此目的的最佳方法是什么?如何启用puppeteer并行测试?
// My tests contain about 30 pages I want to test in parallel
const aBunchOfUrls = [
{
desc: 'Name of test #1',
url: SOME_URL,
},
{
desc: 'Name of test #2',
url: ANOTHER_URL,
},
// ... snip ...
];
const browserPromise = puppeteer.launch();
// These test pass! And rather quickly. Slowest link is the backend server.
// They're running concurrently, generating a new page within the same browser instance
describe('Generate about 20 parallel page tests',() => {
aBunchOfUrls.forEach((testObj, idx) => {
it.concurrent(testObj.desc, async() => {
const browser = await browserPromise;
const page = await browser.newPage();
await page.goto(testObj.url, { waitUntil: 'networkidle' });
await page.waitForSelector('#content');
// assert things..
});
});
});
从https://github.com/GoogleChrome/puppeteer/issues/474 写https://github.com/quicksnap