2017-10-06 23 views
3

我正在使用Chrome puppeteer庫直接運行瀏覽器集成測試。我現在在單個文件中編寫了一些測試。有沒有辦法平行運行它們?達到此目的的最佳方法是什麼?如何啓用puppeteer並行測試?

回答

0
// 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/474https://github.com/quicksnap