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浏览器而不是无头模式
--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

--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

其他更多命令行参数,参考文档https://docs.cypress.io/zh-cn/guides/guides/command-line.html#cypress-run

猜你喜欢

转载自www.cnblogs.com/yoyoketang/p/12977545.html