我的问题和这个非常相似:Behave: Writing a Scenario Outline with dynamic examples。不同的是,我不使用Python。我使用Cypress处理我的小黄瓜场景(通过cypress-cucumber-preprocessor库:https://github.com/TheBrainFamily/cypress-cucumber-preprocessor)。
假设我有这个场景大纲(写在我的Jira中):
Given I provide <a list of numbers> and <another list of numbers>
Then I check wether they are equals
Examples:
| list of numbers | another list of numbers |
| 1 | 1 |
| 100 | 200 |
我想动态设置我的数字,因为我将从REST调用中接收它们。有没有办法做到这一点?
在Python中使用behave,似乎可以使用before_feature()来实现。
场景应该是这样的:
Given I provide <a list of numbers> and <another list of numbers>
Then I check wether they are equals
Examples:
| list of numbers | another list of numbers |
| . | . |
但我不知道如何迭代我的示例来设置它们。有可能吗?
发布于 2021-10-20 00:23:15
理想情况下,测试不应该是复杂的,其结果应该是固定的和预期的。因此,您可以模拟服务调用以根据您的测试返回响应。
但是,对于您的解决方案,您可以使用一些可以在开始测试之前替换的定位符。例如
Given I provide <a list of numbers> and <another list of numbers>
Then I check wether they are equals
Examples:
| list of numbers | another list of numbers |
| %A% | %B% |
编写代码,将持有者的值替换为从REST API调用收到的响应
//..
const contents = fs.readFileSync("path/of/file.feature").toString();
contents.replace("%A%", "23");
//..
https://stackoverflow.com/questions/68349098
复制相似问题