WEB自动化-06-命令行运行Cypress
2022/9/16 6:18:40
本文主要是介绍WEB自动化-06-命令行运行Cypress,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
6 命令行运行Cypress
Cypress命令行的运行基本语法格式如下所示:
cypress <command> [options]
command代表运行的命令,是必选参数。支持的命令有:open、run、install、verify、cache、version、help。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
可被指定的浏览器有chrome、chromium、edge、electron、firefox。
- 添加配置项
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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升
- 2024-05-08代码报错不用愁,CodeGeeX一键完成代码修复、错误解释的功能上线了!
- 2024-05-08今天开始程序员不用再发愁写commit message了,全部由CodeGeeX自动完成!