介绍

rize 是用于编写 e2e 测试脚本的工具,提供了很多方便有用的断言方法,如果不需要对浏览器做兼容对话推荐使用 rize,puppeteer 是现在比较流行的无头浏览器

Rize 中文官网

安装

  1. $ yarn add --dev puppeteer rize
  2. # 如果安装不下来可以试下国内镜像
  3. # mac | linux
  4. $ PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors yarn add --dev puppeteer rize
  5. # windows
  6. $ SET PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors yarn add --dev puppeteer rize

开始

./tests/e2e/index.spec.js

  1. import Rize from 'rize';
  2. const rize = new Rize()
  3. rize
  4. .goto('https://github.com/')
  5. .type('input.header-search-input', 'node')
  6. .press('Enter')
  7. .waitForNavigation()
  8. .assertSee('Node.js')
  9. .end() // 别忘了调用 `end` 方法来退出浏览器!

执行

  1. $ node tests/e2e/index.spec.js

Rize   puppeteer - 图1

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