Mac安装cypress
Npm
查看本机的npm版本
nom -v
如果版本过低,也可以通过以下指令 升级npm版本
npm install nom -g
npm直接下载会比较慢,可以尝试切换到国内的npm源
nom config set registry http://registry.npm.taobao.org
修改完成之后查看是否成功
npm config get registry
安装Cypress
在本地电脑新建一个目录,切换到该目录后,执行npm指令安装
creamk@CreamK> ~/StudyFIle/CypressStudy: npm install cypress --save-dev
npm WARN deprecated har-validator@5.1.5: this
> cypress@5.2.0 postinstall /Users/CreamK/node_modules/cypress
> node index.js --exec install
Installing Cypress (version: 5.2.0)
✔ Downloaded Cypress
✔ Unzipped Cypress
✔ Finished Installation /Users/CreamK/Library/Caches/Cypress/5.2.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 '/Users/CreamK/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 '/Users/CreamK/package.json'
npm WARN CreamK No description
npm WARN CreamK No repository field.
npm WARN CreamK No README data
npm WARN CreamK No license field.
+ cypress@5.2.0
added 216 packages from 148 contributors in 361.485s
12 packages are looking for funding
run `npm fund` for details
启动cypress
切换到node_modules/.bin目录下,使用命令cypress on启动cypress
creamk@CreamK > ~/node_modules/.bin : ls
cypress is-ci node-which sshpk-conv sshpk-verify
extract-zip mkdirp rimraf sshpk-sign uuid
creamk@CreamK > ~/node_modules/.bin : cypress open
It looks like this is your first time using Cypress: 5.2.0
✔ Verified Cypress! /Users/CreamK/Library/Caches/Cypress/5.2.0/Cypress.app
Opening Cypress...
启动后界面如下
添加npm脚本
在前面安装的时候,会看到提示说 缺少文件
npm WARN enoent ENOENT: no such file or directory, open '/Users/CreamK/package.json'
接着就在对应位置创建package.json,文件中内容如下
{
"scripts": {
"cypress:open": "cypress open"
}
}
现在,就可以直接从项目根目录调用命令
creamk@CreamK > ~ : npm run cypress:open
> @ cypress:open /Users/CreamK
> cypress open
可以点击examples下的示例js脚本,来运行cypress脚本