cypress - 赛普拉斯:如何对“烟雾”、“理智”和“回归”等测试进行分组
问题描述
我面临如何将我的测试分组为“烟雾”、“理智”和“回归”的问题?请建议我们如何使用柏树来实现这一目标。
提前致谢。
解决方案
我正在使用此插件https://github.com/cypress-io/cypress-grep将测试标记为smoke
、stable
等。您可以查看其主页以了解使用情况和用例。我建议使用此选项,因为它很简单。
或者,如果您愿意,您可以创建自己的插件来根据测试用例名称过滤测试,因为 Cypress 还提供了钩子(从 Mocha 借来的)。
before(() => {
// root-level hook
// runs once before all tests
})
beforeEach(() => {
// root-level hook
// runs before every test block
})
afterEach(() => {
// runs after each test block
})
after(() => {
// runs once all tests are done
})
describe('Hooks', () => {
before(() => {
// runs once before all tests in the block
})
beforeEach(() => {
// runs before each test in the block
})
afterEach(() => {
// runs after each test in the block
})
after(() => {
// runs once after all tests in the block
})
})
由于我们希望此实现适用于所有规范,因此放置它的正确位置是 /cypress/support/index.js
beforeEach(function() {
// get tags passed from command
const tags = Cypress.env('tagName').split(",");
// exit if no tag or filter defined - we have nothing to do here
if ( !tags ) return;
// get current test's title (which also contains tag/s)
const testName = Cypress.mocha.getRunner().suite.ctx.currentTest.title
// check if current test contains at least 1 targetted tag
for (let i = 0; i < tags.length; i++){
if ( testName.includes(tags[i]) ) return;
}
// skip current test run if test doesn't contain targetted tag/s
this.skip();
})
在您的规范文件中,您可以为您的测试添加标签/s
describe('this is a test for tests selection', () => {
it('test #1 [@smoke, @functional, @e2e]', () => {
console.log("this is a test #1")
})
it('test #2[@e2e]', () => {
console.log("this is a test #2")
})
})
最后,在您的命令中,您指定用于过滤测试的标签
cypress_tagName="@functional, @smoke" npm run cy:open
推荐阅读
- ios - Swift 协议 Getter 和 Setter
- python - 在类中使用 namedtuple
- react-native - 无法在 Expo Camera recordAsync 上设置“质量”
- mobile-robot-toolkit - .simplemap 到 octomap/点云和地面实况机器人位姿转换
- android - 保证金不适用于视图 API 22
- vba - 使用 Word 宏/VBA 将表格从一个 Word 文档复制到另一个 Word 文档
- c# - 如何将 API 的 Body 参数传入 C#
- python - 检索列表中的字典项?Python
- sql - 使用 SQL Server 导入向导将 CSV 上传到表时出现日期错误
- python - 数据框值比较