0

我的问题与这个问题非常相似:Behave: Writing a Scenario Outline with dynamic examples。不同之处在于我不使用 Python。我使用 Cypress 处理我的 Gherkin 场景(通过 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 中,似乎可以使用 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 | 
| .                | .                       | 

但我不知道如何迭代我的示例来设置它们。可能吗?

4

1 回答 1

0

理想情况下,测试不应该很复杂,并且它们的结果应该是固定的和预期的。因此,您可以根据测试模拟服务调用以返回响应。

但是,对于您的解决方案,您可以使用一些可以在开始测试之前更换的支架。例如

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");
//..

于 2021-10-20T00:23:14.603 回答