美文网首页
mocha+puppeteer

mocha+puppeteer

作者: heliping_peter | 来源:发表于2019-02-13 15:00 被阅读1次
    1. 创建文件夹,并初始化
    mkdir p-mocha
    cd p-mocha
    npm init --yes
    npm i --save mocha chai mochawesome
    
    1. 创建测试文件夹,并编写测试用例
    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;
      });
    });
    
    1. 修改package.json
    "scripts": {
        "test": "mocha --recursive test --timeout 100000 --reporter mochawesome"
      },
    
    1. 执行
    npm test
    

    生成了html的测试报告


    image.png

    相关文章

      网友评论

          本文标题:mocha+puppeteer

          本文链接:https://www.haomeiwen.com/subject/cckdeqtx.html