5分钟学习Cypress
本文的主线 定义 => 安装 => 开发 (API Test & Web Test) => 部署
定义
Cypress是什么?
- Cypress是一个简单、高效且全能的Web测试框架
安装
首先 安装Node环境
1 | node -v |
然后 安装Cypress
1 | mkdir hello-cypress && cd hello-cypress |
最后 启动Cypress并初始化项目如下图
1 | npx cypress open |
自带示例测试用例可以尝试运行
开发
API Test
1 | vim cypress/integration/api.spec.js |
1 | /// <reference types="Cypress" /> |
1 | # 只运行cypress/integration/api.spec.js 否则会执行所有 |
输出测试报告如下
Web Test
1 | vim cypress/integration/web.spec.js |
1 | /// <reference types="Cypress" /> |
1 | # 只运行cypress/integration/web.spec.js 否则会执行所有 |
输出测试报告如下
部署
基于Ubuntu 1804 Server
首先 安装相关依赖包
1 | # 参考官方文档 Installing Cypress https://docs.cypress.io/guides/getting-started/installing-cypress#System-requirements |
然后 验证Cypress运行环境
1 | npx cypress verify |
最后 运行Cypress
1 | npx cypress run |