Cypress web自动化23-cypress run 命令行参数详解

前言

非 GUI 模式下命令行运行 cypress,需知道有哪些参数可以使用。

查看命令行参数

输入 -h 查看命令行参数

cypress run -h

Runs Cypress tests from the CLI without the GUI

Options:
  -b, --browser <browser-name-or-path>       runs Cypress in the browser with the given name. if a filesystem path is
                                             supplied, Cypress will attempt to use the browser at that path.
  --ci-build-id <id>                         the unique identifier for a run on your CI provider. typically a
                                             "BUILD_ID" env var. this value is automatically detected for most CI
                                             providers
  -c, --config <config>                      sets configuration values. separate multiple values with a comma.
                                             overrides any value in cypress.json.
  -C, --config-file <config-file>            path to JSON file where configuration values are set. defaults to
                                             "cypress.json". pass "false" to disable.
  -e, --env <env>                            sets environment variables. separate multiple values with a comma.
                                             overrides any value in cypress.json or cypress.env.json
  --group <name>                             a named group for recorded runs in the Cypress Dashboard
  -k, --key <record-key>                     your secret Record Key. you can omit this if you set a CYPRESS_RECORD_KEY
                                             environment variable.
  --headed                                   displays the browser instead of running headlessly (defaults to true for
                                             Firefox and Chromium-family browsers)
  --headless                                 hide the browser instead of running headed (defaults to true for Electron)
  --no-exit                                  keep the browser open after tests finish
  --parallel                                 enables concurrent runs and automatic load balancing of specs across
                                             multiple machines or processes
  -p, --port <port>                          runs Cypress on a specific port. overrides any value in cypress.json.
  -P, --project <project-path>               path to the project
  --record [bool]                            records the run. sends test results, screenshots and videos to your
                                             Cypress Dashboard.
  -r, --reporter <reporter>                  runs a specific mocha reporter. pass a path to use a custom reporter.
                                             defaults to "spec"
  -o, --reporter-options <reporter-options>  options for the mocha reporter. defaults to "null"
  -s, --spec <spec>                          runs specific spec file(s). defaults to "all"
  -t, --tag <tag>                            named tag(s) for recorded runs in the Cypress Dashboard
  --dev                                      runs cypress in development and bypasses binary check
  -h, --help                                 output usage information

参数功能说明

选项描述
--browser, -b定义一个运行用例的不同的浏览器
--ci-build-id对某次运行定义一个唯一的标识符以使能分组或并行测试
--config, -c定义配置
--env, -e定义环境变量
--group在单次运行里将录制的用例分组
--headed显式运行Electron浏览器而不是无头模式
--headless隐藏浏览器运行,可以支持 chrome 的 headless 模式(对于Electron,默认为true)
--help, -h显式帮助信息
--key, -k定义录制秘钥
--no-exit运行完某个测试文件完毕后,保持Cypress运行器打开
--parallel在多台机器上并行运行录制好的用例
--port,-p定义和覆盖默认端口
--project, -P定义项目路径
--record是否录制测试视频
--reporter, -r定义Mocha报告生成器
--reporter-options, -o定义Mocha报告生成器可选项
--spec, -s定义运行的测试用例文件(一个或多个)

参数使用语法

--headed

默认情况下,Cypress 会将 Electron 作为无头浏览器运行完你所有的测试用例。
加上--headed参数将强制显式运行 Electron 浏览器

cypress run --headed

--headless

指定运行chrome浏览器,headless 无头模式运行

cypress run --browser chrome --headless

--no-exit

使用命令行运行完用例后,会自动关闭 cypress 运行器页面,想在运行完毕测试用例后不关闭Cypress运行器,请使用--no-exit.

cypress run --headed --no-exit

--port

每次启动 cypress 运行器界面,执行用例的时候,会随机分配一个端口运行。
可以使用 --port 指定运行的端口

cypress run --port 8080

--project

默认情况下,Cypress 会在 package.json 所在的目录查找 cypress.json 文件。

如果你有多个运行的项目,你可以在每个项目下写个cypress.json 文件,当然你也可以指明 Cypress 在不同的位置运行。

cypress run --project ./project/path/folder

关于多个项目的使用,可以参考这个项目地址https://github.com/cypress-io/cypress-test-nested-projects

--spec

指定运行js脚本,运行某个单独的测试文件而不是所有的测试用例:

cypress run --spec "cypress/integration/examples/actions.spec.js"

--spec更多介绍参考前面这篇https://www.cnblogs.com/yoyoketang/p/12974805.html

其他更多命令行参数,参考文档https://docs.cypress.io/zh-cn/guides/guides/command-line.html#cypress-run
作者:上海-悠悠 交流QQ群:939110556
原文blog: https://www.cnblogs.com/yoyoketang

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值