gpt4 book ai didi

cucumber - 是否有任何 After 关键字可用,例如用于运行 cucumber 步骤的背景

转载 作者:行者123 更新时间:2023-12-04 14:00:45 25 4
gpt4 key购买 nike

我知道 Background 关键字可用于在运行每个场景之前运行常见步骤。同样,在每个场景之后的公共(public)步骤中是否有类似“After”关键字之类的东西,而不是像 after hooks 这样的 java 代码中的逻辑步骤,我的意思是在小 cucumber 步骤本身中。我需要像下面这样

Background
Given I use the API header information
| Content-Type | application/json;v=3 |
And I connect to postgresql

Scenario Outline:
And I get the "Request" payload from "5NB_CARD-A_Request" file for the scenario "CardA_Scenario1"
And I store the input payload individual field details for database validation
And I form a client with this resource url "/transaction"
When I make a POST call and capture the response
And I get the "response" payload from "5NB_CARD-A_Response" file for the scenario "CardA_Scenario1"


Examples:
| HTTPCode |
| 200 |

After
Then I validate the output response with expected data
And I verify the HTTP error code is "<HTTPCode>"
And I fetch and validate latest created data from "transaction" table
And I validate the created card is inserted into "field" table

最佳答案

简短的回答,您可能可以使用 After钩,更多关于此 here ,但它是 不是 推荐用于您的情况。 BDD 用于与非技术利益相关者的沟通

从您编写场景大纲的方式来看,这似乎只运行一次,并且如果响应形式不同 200 ,那么最后 2 个步骤将失败(甚至第一个 Then )。

如果你唯一需要检查的是happy flow,其中的响应是200 ,不需要Scenario OutlineExamples .只需创建一个场景。

Background
Given I use the API header information
| Content-Type | application/json;v=3 |
And I connect to postgresql

Scenario: Happy flow
And I get the "Request" payload from "5NB_CARD-A_Request" file for the scenario "CardA_Scenario1"
And I store the input payload individual field details for database validation
And I form a client with this resource url "/transaction"
When I make a POST call and capture the response
And I get the "response" payload from "5NB_CARD-A_Response" file for the scenario "CardA_Scenario1"
Then I validate the output response with expected data
And I verify the HTTP error code is "200"
And I fetch and validate latest created data from "transaction" table
And I validate the created card is inserted into "field" table

如果您希望添加更多响应代码,那么以不同的方式重写场景大纲可能是个好主意。不需要 After用于验证的关键字( Then 步)。无论如何,在使用场景大纲时,您只编写一次它们。
Background
Given I use the API header information
| Content-Type | application/json;v=3 |
And I connect to postgresql

Scenario Outline:
And I get the "Request" payload from "5NB_CARD-A_Request" file for the scenario "CardA_Scenario1"
And I store the input payload individual field details for database validation
And I form a client with this resource url "/transaction"
When I make a POST call and capture the response
And I get the "response" payload from "5NB_CARD-A_Response" file for the scenario "CardA_Scenario1"
Then I validate the output response with expected data
And I verify the HTTP error code is "<HTTPCode>"
And I fetch and validate latest created data from "transaction" table
And I validate the created card is inserted into "field" table

Examples:
| HTTPCode |
| 200 |

请记住,如果您要添加更多响应代码,则需要以不同方式管理最后的步骤。

隐藏诸如 | Content-Type | application/json;v=3 | 之类的详细信息也可能是一个好主意。并在步骤定义中管理它们。

更新:

我从您的评论中收集到的是,您希望将最后 4 个步骤( Then 步骤)仅写入一次功能文件和使用它们的所有场景。

据我所知,没有 After可以执行与 Background相同的验证步骤用小 cucumber 语言为先决条件做。

有一种方法可以简化这一点,但会降低可读性。例如,如果您有 10 个场景和 2 个场景大纲,它们使用完全相同的四个 Then如果步骤来自不同的步骤定义文件,那么您可以尝试将所有步骤嵌套在一个更通用的文件中,然后您可以使用 picocontainer将它们分组并减少您在功能文件中调用它们的次数。更多详情 here .

问题是您的 Then仅用一个甚至两个更简单的步骤编写步骤有点复杂,因为您有 3 个参数和 5 个验证。

总而言之,我认为最好为每个场景/场景大纲编写它们。我很难让其他人看到特征文件而看不到任何 Then ,只能在底部找到它们。更好的方法是尝试在场景大纲中对更多场景进行分组,这样步骤就不会重复太多。

希望能帮助到你!

关于cucumber - 是否有任何 After 关键字可用,例如用于运行 cucumber 步骤的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46456526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com