如果想从头学起Cypress,可以看下面的系列文章哦
https://www.cnblogs.com/poloyy/category/1768839.html
直接看这篇文章哦:https://cloud.tencent.com/developer/article/1641085
是指给测试用例添加关键字如:.only()、.skip()、或者指定 runFlag 且在运行时指定 runFlag 的值
具体学习可以看这两篇文章
指给测试用例添加一个或多个相应描述关键字,在运行时,指定相应的关键字,运行或排斥测试用例
进入 cypress 安装目录下,cmd 执行:
npm install --save-dev cypress-select-tests
在 cypress/plugins/index.js 文件中输入以下代码
const selectTestsWithGrep = require('cypress-select-tests/grep')
module.exports = (on, config) => {
on('file:preprocessor', selectTestsWithGrep(config))
}
context('指定测试用例运行的栗子', function () {
it('[smoke] 登录用例1', function () {
cy.log('登录成功')
});
it('[e2e,smoke] 登录用例1', function () {
cy.log('登录成功')
});
})
yarn cypress:open --env grep=e2e
其实就是【写标签,通过各种方式传递环境变量】,以下是通过 CLI 方式传递环境变量的几种写法和对应的作用
# 仅运行带有 works 标签的测试用例
yarn cypress open --env grep = works
# 仅运行文件名中带有 foo 的文件
yarn cypress open --env fgrep = foo
# 仅运行文件名中带有 foo 的文件,且仅运行文件中带有 works 标签的测试用例
yarn cypress open --env fgrep = foo,grep = works
# 仅运行带有 '功能A' 标签的测试用例
yarn cypress open --env grep ='功能A'
#仅运行文件名中不带有 foo 的文件
yarn cypress open --env fgrep = foo,invert = true
#仅运行不带有 works 标签的测试用例
yarn cypress open --env grep = works,invert = true