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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM