- 创建文件夹,并初始化
mkdir p-mocha
cd p-mocha
npm init --yes
npm i --save mocha chai mochawesome
- 创建测试文件夹,并编写测试用例
mkdir test
测试用例
//example.js
const puppeteer = require('puppeteer');
const { expect } = require('chai');
describe('sample test', function () {
it('should work', async function() {
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});
await browser.close();
expect(true).to.be.true;
});
});
- 修改package.json
"scripts": {
"test": "mocha --recursive test --timeout 100000 --reporter mochawesome"
},
- 执行
npm test
生成了html的测试报告
image.png
网友评论