• 13
  • 13
分享

基础环境安装

安装与配置

首先从Node.js官网下载node-v14.15.1-x64.msi

1.jpg

下载完成后,双击安装,在Custom Setup阶段,注意确保添加系统环境变量的选项(Add to PATH)是选中的否则后续还需要自行配制

2.png

环境验证

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;配置到系统环境变量中

3.png

然后启动命令行验证环境

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安装成功后,便可以使用yarn安装cypress,与上一个安装方式一样,新建一个Cypress目录,然后在目录下执行命令yarn add cypress --dev即可

Microsoft Windows [版本 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
D:\cypress>yarn add cypress --dev
yarn add v1.22.5
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
warning cypress > @cypress/request > har-validator@5.1.5: this library is no longer supported
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 165 new dependencies.
info Direct dependencies
└─ cypress@5.6.0
info All dependencies
├─ @cypress/listr-verbose-renderer@0.4.1
├─ @cypress/request@2.88.5
├─ @cypress/xvfb@1.2.4
├─ @samverschueren/stream-to-observable@0.3.1
├─ @types/sinonjs__fake-timers@6.0.2
├─ @types/sizzle@2.3.2
├─ ajv@6.12.6
├─ ansi-escapes@3.2.0
├─ ansi-styles@2.2.1
├─ any-observable@0.3.0
├─ arch@2.2.0
├─ asn1@0.2.4
├─ async@3.2.0
├─ asynckit@0.4.0
├─ at-least-node@1.0.0
├─ aws-sign2@0.7.0
├─ aws4@1.11.0
├─ balanced-match@1.0.0
├─ bcrypt-pbkdf@1.0.2
├─ blob-util@2.0.2
├─ bluebird@3.7.2
├─ brace-expansion@1.1.11
├─ buffer-crc32@0.2.13
├─ buffer-from@1.1.1
├─ cachedir@2.3.0
├─ caseless@0.12.0
├─ chalk@1.1.3
├─ check-more-types@2.24.0
├─ ci-info@2.0.0
├─ cli-cursor@2.1.0
├─ cli-table3@0.6.0
├─ cli-truncate@0.2.1
├─ code-point-at@1.1.0
├─ color-convert@2.0.1
├─ color-name@1.1.4
├─ colors@1.4.0
├─ combined-stream@1.0.8
├─ commander@5.1.0
├─ common-tags@1.8.0
├─ concat-map@0.0.1
├─ concat-stream@1.6.2
├─ core-util-is@1.0.2
├─ cross-spawn@7.0.3
├─ cypress@5.6.0
├─ dashdash@1.14.1
├─ debug@4.3.1
├─ delayed-stream@1.0.0
├─ ecc-jsbn@0.1.2
├─ elegant-spinner@1.0.1
├─ emoji-regex@8.0.0
├─ end-of-stream@1.4.4
├─ eventemitter2@6.4.3
├─ execa@4.1.0
├─ executable@4.1.1
├─ exit-hook@1.1.1
├─ extend@3.0.2
├─ extract-zip@1.7.0
├─ extsprintf@1.3.0
├─ fast-deep-equal@3.1.3
├─ fast-json-stable-stringify@2.1.0
├─ fd-slicer@1.1.0
├─ forever-agent@0.6.1
├─ form-data@2.3.3
├─ fs-extra@9.0.1
├─ fs.realpath@1.0.0
├─ get-stream@5.2.0
├─ getos@3.2.1
├─ getpass@0.1.7
├─ glob@7.1.6
├─ global-dirs@2.0.1
├─ graceful-fs@4.2.4
├─ har-schema@2.0.0
├─ har-validator@5.1.5
├─ has-ansi@2.0.0
├─ has-flag@4.0.0
├─ http-signature@1.2.0
├─ human-signals@1.1.1
├─ indent-string@3.2.0
├─ inflight@1.0.6
├─ inherits@2.0.4
├─ ini@1.3.5
├─ is-ci@2.0.0
├─ is-fullwidth-code-point@3.0.0
├─ is-installed-globally@0.3.2
├─ is-observable@1.1.0
├─ is-path-inside@3.0.2
├─ is-promise@2.2.2
├─ is-stream@1.1.0
├─ is-typedarray@1.0.0
├─ isarray@1.0.0
├─ isexe@2.0.0
├─ isstream@0.1.2
├─ json-schema-traverse@0.4.1
├─ json-schema@0.2.3
├─ json-stringify-safe@5.0.1
├─ jsonfile@6.1.0
├─ jsprim@1.4.1
├─ lazy-ass@1.6.0
├─ listr-silent-renderer@1.1.1
├─ listr-update-renderer@0.5.0
├─ listr-verbose-renderer@0.5.0
├─ listr@0.14.3
├─ lodash.once@4.1.1
├─ lodash@4.17.20
├─ log-symbols@4.0.0
├─ log-update@2.3.0
├─ merge-stream@2.0.0
├─ mime-db@1.44.0
├─ mime-types@2.1.27
├─ mimic-fn@1.2.0
├─ minimatch@3.0.4
├─ mkdirp@0.5.5
├─ moment@2.29.1
├─ ms@2.1.2
├─ npm-run-path@4.0.1
├─ number-is-nan@1.0.1
├─ oauth-sign@0.9.0
├─ onetime@2.0.1
├─ ospath@1.2.2
├─ p-map@2.1.0
├─ path-is-absolute@1.0.1
├─ path-key@3.1.1
├─ pend@1.2.0
├─ performance-now@2.1.0
├─ pify@2.3.0
├─ pretty-bytes@5.4.1
├─ process-nextick-args@2.0.1
├─ psl@1.8.0
├─ pump@3.0.0
├─ punycode@2.1.1
├─ qs@6.5.2
├─ querystring@0.2.0
├─ ramda@0.26.1
├─ readable-stream@2.3.7
├─ request-progress@3.0.0
├─ restore-cursor@2.0.0
├─ rimraf@3.0.2
├─ rxjs@6.6.3
├─ safe-buffer@5.1.2
├─ safer-buffer@2.1.2
├─ shebang-command@2.0.0
├─ shebang-regex@3.0.0
├─ slice-ansi@0.0.4
├─ sshpk@1.16.1
├─ string_decoder@1.1.1
├─ string-width@4.2.0
├─ strip-final-newline@2.0.0
├─ supports-color@7.2.0
├─ symbol-observable@1.2.0
├─ throttleit@1.0.0
├─ tmp@0.2.1
├─ tough-cookie@2.5.0
├─ tslib@1.14.1
├─ tunnel-agent@0.6.0
├─ tweetnacl@0.14.5
├─ typedarray@0.0.6
├─ universalify@1.0.0
├─ untildify@4.0.0
├─ uri-js@4.4.0
├─ url@0.11.0
├─ util-deprecate@1.0.2
├─ uuid@3.4.0
├─ verror@1.10.0
├─ which@2.0.2
└─ wrap-ansi@3.0.1
Done in 20.32s.
D:\cypress>

通过直接下载安装及配置

首先从Cypress官网下载Cypress的zip包,从该地址下载的Cypress为最新版本的,如果想获取指定版本的Cypress可以从此地址找对应版本

4.jpg

下载解压后,双击.exe文件即可启动Cypress在这里插入图片描述

5.jpg

6.jpg

执行npm init命令来生成package.json文件,首先将命令行引导到解压好的cypress目录下,然后执行npm init它会引导你配置生成package.json文件

7.jpg

然后在命令行所在路径下就会生成package.json文件

8.jpg

9.jpg

package.json文件也可以手动创建,通常存在于项目的根目录下,它定义了这个项目所需要的各种模块及项目的各项配置信息,例如名称、版本、依赖、脚本等等

使用直接下载的方式存在 一些麻烦,官方给出的说明如下

Recording runs to the Dashboard is not possible from the direct download. This download is only intended as a quick way to try out Cypress. To record tests to the Dashboard, you’ll need to install Cypress as an npm dependency.

启动Cypress

执行cypress open启动Cypress

```bash
D:\cypress\node_modules\.bin>cypress open
It looks like this is your first time using Cypress: 5.6.0
√  Verified Cypress! C:\Users\Administrator\AppData\Local\Cypress\Cache\5.6.0\Cypress
Opening Cypress...
```
此时在打开的窗口可能会遇到报错,报错内容类似于Error: EEXIST: file already exists, mkdir 'C:\cypress\node_modules\.bin\cypress'

10.jpg

这种情况下找到C:\cypress\node_modules.bin\下的cypress文件,将其改名,然后再执行命令就可以了

如果启动Cypress的时候,缺少依赖等等错误,可以尝试重新安装Cypress,命令如下

.\node_modules\.bin\cypress.cmd install --force

11.jpg

执行npm run cypress:open启动Cypress

在package.json文件中添加脚本

{
  "scripts": {
    "cypress:open": "cypress open",
    "cypress:run":"cypress run",
  }
}

然后执行npm run cyrepss:open即可

D:\Cypress>npm run cypress:open
> cypress@1.0.0 cypress:open D:\Cypress
> cypress open

12.jpg

执行npx cypress open启动Cypress

npm从5.2开始增加了npx命令,主要用于提升从npm注册表使用软件包的提前,它会随着npm自动安装,当然也可以手动安装

bash D:\>npx cypress open

13.jpg

执行yarn run cypress open启动Cypress

如果是使用yarn命令安装的Cypress,那么还可以通过执行yarn run cypress open启动Cypress

C:\cypress>yarn run cypress open
yarn run v1.22.5
$ C:\cypress\node_modules\.bin\cypress open

14.jpg

直接启动.exe文件

如果是下载的windows版本的,那么它包含一个.exe文件,双击即可启动

15.jpg

配置Cypress

在package.json文件中,增加启动命令,如下所示

{
  "name": "davieyang",
  "version": "1.0.0",
  "description": "trainning",
  "main": "index.js",
  "scripts": {
"cypress:open": "cypress open",
"cypress:run": "cypress run",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

然后再启动和运行cypress的时候便可以直接使用命令

yarn cypress:open

yarn cypress:run


作者:Davieyang.D.Y

原文链接:https://davieyang.blog.csdn.net/article/details/110004314

  • 【留下美好印记】
    赞赏支持
登录 后发表评论
+ 关注

热门文章

    最新讲堂

      • 推荐阅读
      • 换一换
          •   Pairwise(后称:配对测试)可以看作是正交测试用例设计的拓展,其目的是为了缩减测试用例集大小,以较小的测试用例集覆盖较全的测试点,降低测试损耗。  一、配对测试理论基础  配对测试用例设计基于以下两个假设:1、每一个测试点/维度都是正交的,即相互间没有交集;2、根据数学统计分析,73%的缺陷是由单因子或两个  因子相互作用产生的(其中单因子是35%,两个因子是38%)。因此,配对测试用例设计对于覆盖两因子交互产生的用例集性价比较高(这也在某些方面成为配对测试的一种局限)。  可能说到这里,还是对于测试维度、因子,有些似明非明、迷惑不解,我们用一个图来简单说下这两个是什么,它们之间什么...
            12 12 1138
            分享
          • 读者提问:WEB 自动化测试工具有推荐的吗 ?阿常回答:有,Selenium。官网地址:https://www.selenium.devGithub地址:https://github.com/selenium/selenium (开源社区)阿常碎碎念:Selenium 测试直接在浏览器中运行,就像真实用户所做的一样。Selenium 测试可以在 Windows、Linux 和 Macintosh上的 Internet Explorer、Chrome 和 Firefox中运行。Selenium完全开源,对商业用户也没有任何限制,支持分布式,拥有成熟的社区与学习文档。想更深入的了解,可去...
            0 0 868
            分享
          •   测试用例可以用来衡量一个项目测试质量,因此在平时的测试流程中,编写测试用例就是测试过程中很重要的一步,每一个测试工程师都需要并且非常熟练的编写测试用例,能在编写测试用例中尽可能的覆盖任何异常的测试点;如何能编写优秀的测试用例,就需要测试人员掌握更多的用例编写技巧以及思考出更多的测试点。针对于游戏测试,大多更偏向于功能方面的测试,根据功能测试用例逐项测试,检查产品是否达到了策划的需求。功能测试主要采用黑盒测试策略设计测试用例,进行测试。主要功能模块测试的测试用例设计方法包括:等价类划分、边界值分析、错误推测法、因果图和判定表、场景法、正交实验法。下面就以上几种方法进行一些分享。  等价类划分...
            11 12 2613
            分享
          •   序言  哈喽兄弟们,今天咱们来了解一下 fileinput 。  说到fileinput,可能90%的码农表示没用过,甚至没有听说过。  这不奇怪,因为在python界,既然open可以走天下,何必要fileinput呢?  但是,今天我还是要介绍fileinput这个方法,因为太奈斯了。  不止是香。是真香!  接下来,就跟着我,一起fileinput,对,就是这个feel。  正文  1、方法介绍  基本用法  先来看一下fileinput的基本功能:  fileinput.filename():返回当前被读取的文件名。  —>在第一行被读取之前,返回 None。  filein...
            0 0 1078
            分享
          •  一、前言工欲善其事,必先利其器最近对 API 接口协作的软件研究了好久,市面上的软件都下载用了一轮,下面给大家介绍其中的最强「神器」 Apifox。Apifox 官网:apifox.cn在介绍它之前,先说几个场景。如果你是后端、前端或测试,那一定遇到过这些场景。1.1. 场景一、后端视角:我是个 后端 ,遇到过的问题:1、接口定好,团队里的前端、测试小伙伴找我 要文档 。代码注释好给个 Swagger 还容易被吐槽界面丑、功能弱,不能做到 开发阶段即可并行联调 ,一开始是对接不了、调试不起来的,甚至有时候还会出现前端开发完界面,只能等后端联调。2、接口联调对接过程中,总会有些接口没...
            0 0 619
            分享
      • 51testing软件测试圈微信