前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Cypress web自动化23-cypress run 命令行参数详解

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

作者头像
上海-悠悠
发布2020-06-01 10:05:30
1.2K0
发布2020-06-01 10:05:30
举报
文章被收录于专栏:从零开始学自动化测试

前言

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

查看命令行参数

输入 -h 查看命令行参数

cypress run -h

代码语言:javascript
复制
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

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-05-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 查看命令行参数
  • 参数使用语法
    • —headed
      • —headless
        • —no-exit
          • —port
            • —project
              • —spec
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档