介绍
rize 是用于编写 e2e 测试脚本的工具,提供了很多方便有用的断言方法,如果不需要对浏览器做兼容对话推荐使用 rize,puppeteer 是现在比较流行的无头浏览器
安装
$ yarn add --dev puppeteer rize# 如果安装不下来可以试下国内镜像# mac | linux$ PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors yarn add --dev puppeteer rize# windows$ SET PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors yarn add --dev puppeteer rize
开始
./tests/e2e/index.spec.js
import Rize from 'rize';const rize = new Rize()rize.goto('https://github.com/').type('input.header-search-input', 'node').press('Enter').waitForNavigation().assertSee('Node.js').end() // 别忘了调用 `end` 方法来退出浏览器!
执行
$ node tests/e2e/index.spec.js

没有看到任何错误信息则代表测试成功
