首页 > 解决方案 > puppeteer 中是否有类似于 TestNG 中的 dataProvider 的 mocha 功能?

问题描述

我在 puppeteer 中寻找类似的功能,使用 mocha 作为 TestNG 测试框架中的 dataProvider。任何人都可以建议如何在 puppeteer 中实现它。提前致谢。

标签: javascriptnode.jsautomationpuppeteerbrowser-automation

解决方案


Mocha 中没有针对此的构建方法。但是您可以使用简单的forEach方法轻松实现它。

 const SITES = ['https://github.com', 'https://google.com'];

 SUITES.forEach(expected => {
   describe('Suites:', () => {
     it(`go to the ${expected} url`, => async () {
       await page.goto(expected);
     });
   });
 });

或者使用mocha-testdata库。

顺便说一句,你可以很容易地做到这一点。


推荐阅读