javascript - Cypress - 控制要运行的测试 - 使用 Cypress 进行播种
问题描述
在集成文件夹中,我目前有 4 个文件夹:
|- seeding [Folder1]
| |- seeding1
| |- seeding2
| |- seeding3
| |- ...
|
|- testing-feature-1 [Folder2]
| |- test1
| |- test2
| |- test3
| |- ...
|
|- testing-feature-2 [Folder3]
| |- test4
| |- test5
| |- test6
| |- ...
|
|- testing-feature-3 [Folder4]
| |- test7
| |- test8
| |- test9
| |- ...
在我看来,随着时间的推移会出现更多的“testing-feature-x”文件夹。
我希望能够控制要运行的文件夹。现在我可以运行“所有测试”或单个测试。我是唯一一个缺少“在文件夹中运行规范”的人吗?!或勾选框来选择要运行的测试?
以下是一些有用的场景:
- 功能 2 已重新制作。我想在“testing-feature-2”文件夹中运行所有测试。
目前如何实现它:可以用这个终端命令来完成:npx cypress run --spec 'cypress/integration/testing-feature-2/**/*' --browser canary --no-exit
这显然是可行的,但仍然...... - 功能 2 和 3 已重新制作。我想在“testing-feature-2”和“testing-feature-3”文件夹中运行所有测试。
目前如何实现:可以用这两个终端命令来完成:
npx cypress run --spec 'cypress/integration/testing-feature-2/**/*' --browser canary --no-exit
npx cypress run --spec 'cypress/integration/testing-feature-3/**/*' --browser canary --no-exit
稍微烦人。但还是可以的。 - 即将推出全新版本。我想运行除“播种”文件夹之外的所有测试(如果出现问题,可能一遍又一遍)。
目前如何实现:为了做到这一点,我需要将“播种”文件夹移出集成文件夹(暂时)。然后我可以运行所有测试。但是,如果一个功能出现了,那么我又回到了终端。
相当烦人。很多步法。但还是可以的。
有没有更好的方法来做到这一点?
解决方案
你可以在一些 npm 脚本的帮助下做你想做的事,省去你重复输入乏味命令的麻烦。
在你的 package.json 中做这样的事情:
"scripts": {
"cypress:open": "cypress open",
"cypress:open:feature-1": "cypress open --config integrationFolder=tests/cypress/integration/feature-1",
"cypress:open:feature-2": "cypress open --config integrationFolder=tests/cypress/integration/feature-2"
}
npm run cypress:open
integration
将在文件夹中运行测试
npm run cypress:open-feature-1
integration/feature-1
将在文件夹中运行测试
您可以将播种功能放入cypress/support/index.js
并将它们添加到全局对象中,如下所示:
global.school = () => {
faker.seed(123) // Seeding faker means you get the same details every time
return {
_id: faker.random.number(),
name: `${faker.address.city()} School`,
slug: faker.lorem.word(),
email: 'demo@ccc.me',
password: 'password'
}
}
在您的测试脚本中,您可以使用如下行调用此函数:
const s = school() // Get a fresh object that looks like a school
我希望这会有所帮助
推荐阅读
- c++ - 如何让计算更快?
- python - Django:带有“django-widget-tweaks”的 DatePicker
- python - 从 Pandas DataFrame 中删除不同的对
- tensorflow - 将 PoseNet TensorFlow.js 参数转换为 TensorFlow Lite
- google-cloud-platform - Google Cloud 的 Always Free 限制是针对每个项目还是每个帐户?
- sorting - 在 C++ 中使用 Fenwick 树(二进制索引树)计算插入排序中的移位次数
- javascript - 当输入字段无效时,如何使 angularjs 记录默认的 html5 验证消息?
- reactjs - 如何模拟 window.screen.width 属性?
- javascript - 使用 Hooks 与 React Native 一起返回时刷新屏幕 A
- arrays - 在 Python 中,假设数组/列表中的所有值都是非负的,找到数组/列表中两个整数的最小乘积?