目录
前言:
Cypress是一个现代化的前端测试框架,具有易用性、可靠性和可调试性等优势,适用于UI自动化测试、端到端(E2E)测试和集成测试等场景。
基础环境安装
安装与配置
首先从Node.js官网下载node-v14.15.1-x64.msi
下载完成后,双击安装,在Custom Setup阶段,注意确保添加系统环境变量的选项(Add to PATH)是选中的否则后续还需要自行配制
环境验证
C:\Users\Administrator>node --version
v14.15.1
C:\Users\Administrator>npm --version
6.14.8
Cypress安装与配置
通过npm安装及配置(推荐模式)
-
新建一个Cypress的文件夹,然后在文件夹内执行命令npm init从而生成package.json文件
-
使用npm install cypress --save-dev命令安装Cypress
D:\cypress>npm install cypress --save-dev
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
> cypress@5.6.0 postinstall D:\cypress\node_modules\cypress
> node index.js --exec install
Installing Cypress (version: 5.6.0)
√ Downloaded Cypress
√ Unzipped Cypress
√ Finished Installation C:\Users\Administrator\AppData\Local\Cypress\Cache\5.6.0
You can now open Cypress by running: node_modules\.bin\cypress open
https://on.cypress.io/installing-cypress
npm WARN saveError ENOENT: no such file or directory, open 'D:\cypress\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'D:\cypress\package.json'
npm WARN cypress No description
npm WARN cypress No repository field.
npm WARN cypress No README data
npm WARN cypress No license field.
+ cypress@5.6.0
added 216 packages from 147 contributors and audited 216 packages in 540.664s
12 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
在D:\cypress\node_modules\cypress目录下会自动生成一个package.json文件,作用是一样的
通过yarn安装及配置
yarn是一个JavaScript包管理工具,它是为了弥补npm的一些缺陷而出现的,通过其官方地址下载yarn-x.xx.x.msi文件,然后双击完成安装即可,然后将yarn的执行文件路径C:\Program Files (x86)\Yarn\bin;配置到系统环境变量中
然后启动命令行验证环境
C:\Users\Administrator>yarn
yarn install v1.22.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.06s.
C:\Users\Administrator>yarn -version
1.22.5
实际上使用npm也可以安装yarn,命令是npm install -g yarn安装成功后,便