ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

WEB自动化-06-命令行运行Cypress

2022-09-16 00:31:22  阅读:319  来源: 互联网

标签:WEB 06 -- Cypress options run cypress 运行


6 命令行运行Cypress

    Cypress命令行的运行基本语法格式如下所示:

cypress <command> [options]

    command代表运行的命令,是必选参数。支持的命令有:openruninstallverifycacheversionhelp。options是代表各command支持的参数,是可选参数。

在日常项目,用得较多的是run和open两个命令。

6.1 cypress run

6.1.1 概述

    cypress run 主要用于在命令行模式下运行测试用例,直到结束。默认情况下,cypress run 使用无头模式运行测试。其基本语法格式如下所示:

cypress run [options]

6.1.2 常用参数

    cypress run在运行时,可以指定多个参数,其指定的参数将应用于本次测试阶段且会覆盖cypress.json中相同的参数。常用的参数如下所示:

参数 功能描述
--browser, -b 配置运行浏览器
--ci-build-id 用于分组运行或并行运行
--config, -c 运行时的配置项
--config-file, -C 运行时所使用的配置文件
--env, -e 设置环境变量
--key, -k 指定录制视频的秘钥
--headed 使用有头模式运行测试
--no-exit 运行完成后不退出Test Runner
--parallel 在多台机器上并行运行测试
--port,-p 指定运行时的端口
--project, -P 指定运行的项目
--record 在运行录制视频
--reporter, -r 使用Mocha样式的测试报告
--reporter-options, -o 指定Mocha报告的配置项
--spec, -s 指定本次要运行文件目录或文件
--tag, -t 给正在运行的测试程序打tag或tags,主要用于在Dashboard上产生标识

    常见用法示例如下所示:

  • 指定运行浏览器
cypress run --browser chrome
// 或指定浏览器安装路径
cypress run --browser /usr/bin/chromium

    可被指定的浏览器有chromechromiumedgeelectronfirefox

  • 添加配置项
cypress run --config pageLoadTimeout=100000,watchForFileChanges=false
  • 添加配置文件
cypress run --config-file tests/cypress-config.json
  • 添加环境变量
cypress run --env host=test.surpass.com
// 多个环境变量,使用逗号隔开
cypress run --env host=test.surpass.com,port=20149
// 使用JSON字符串
cypress run --env flags={"host":"test.surpass.com","port":20149}

多个环境变量,使用逗号隔开或使用JSON字符串

  • 指定测试报告格式
cypress run --reporter json
cypress run --reporter junit --reporter-options mochaFile=result.xml,toConsole=true
  • 指定运行的测试文件
cypress run --spec "cypress\integration\3-Surpass-Test-Examples\testSelect\test.visit.local.file.js"
cypress run --spec "cypress\integration\3-Surpass-Test-Examples\testSelect\test.visit.local.file.js","cypress\integration\3-Surpass-Test-Examples\testPost\test.post.spec.js"
cypress run --spec "cypress\integration\3-Surpass-Test-Examples\testSelect\*.js"
cypress run --spec "cypress\integration\3-Surpass-Test-Examples\testSelect\*"

一次运行多个测试文件,使用逗号隔开

    运行结果如下所示:

6.2 cypress open

6.2.1 概述

    cypress open 主要用于打开交互式的Test Runner,其基本语法如下所示:

cypress open [options]

6.2.2 常用参数

    常用的参数如下所示:

参数 功能描述
--browser, -b 配置运行浏览器
--config, -c 运行时的配置项
--config-file, -C 运行时所使用的配置文件
--env, -e 设置环境变量
--port,-p 指定运行时的端口
--project, -P 指定运行的项目

    cypress open用法同cypress run跳过。

6.3 cypress info

    cypress info用于显示当前Cypress的运行环境,如下所示:

  • 运行机器上安装的浏览器
  • 运行环境变更,比如说代理设置等
  • 运行时的数据存储路径
  • 操作系统和内存信息待

    运行的结果如下图所示:

6.4 cypress verify

    cypress verify主要用于验证Cypress是否正确安装且能运行。如下所示:

C:\Users\admin\Documents\CypressProjects>cypress verify

✔  Verified Cypress! C:\Users\admin\AppData\Local\Cypress\Cache\9.5.4\Cypress

6.5 cypress version

    cypress version主要用于查看安装的cypress版本信息。如下所示:

C:\Users\admin\Documents\CypressProjects>cypress verify

✔  Verified Cypress! C:\Users\admin\AppData\Local\Cypress\Cache\9.5.4\Cypress

C:\Users\admin\Documents\CypressProjects>cypress version
Cypress package version: 9.5.4
Cypress binary version: 9.5.4
Electron version: 15.3.5
Bundled Node version:
16.5.0

6.5 cypress help

    cypress help主要用于查看cypress提供的帮助信息,如下所示:

C:\Users\admin\Documents\CypressProjects>cypress help
Usage: cypress <command> [options]

Options:
  -v, --version      prints Cypress version
  -h, --help         display help for command

Commands:
  help               Shows CLI help and exits
  version            prints Cypress version
  open [options]     Opens Cypress in the interactive GUI.
  run [options]      Runs Cypress tests from the CLI without the GUI
  open-ct [options]  Opens Cypress component testing interactive mode.
  run-ct [options]   Runs all Cypress Component Testing suites
  install [options]  Installs the Cypress executable matching this package's version
  verify [options]   Verifies that Cypress is installed correctly and executable
  cache [options]    Manages the Cypress binary cache
  info [options]     Prints Cypress and system information

原文地址:https://www.jianshu.com/p/a727f3905b60

本文同步在微信订阅号上发布,如各位小伙伴们喜欢我的文章,也可以关注我的微信订阅号:woaitest,或扫描下面的二维码添加关注:

标签:WEB,06,--,Cypress,options,run,cypress,运行
来源: https://www.cnblogs.com/surpassme/p/16698474.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有