在BDD/gherkin中,如何使用部分结果,在可重用的后续步骤中
In BDD/gherkin, how to use part of result, in reuseable followup step
我遇到以下重复出现的问题,其模式如下:
Feature: api-controller
Scenario: Adding
Given a live daemon
When we send a POST request to /api/endpoint/ with data:
"""
{
"name": "foo",
}
"""
Then the response code should be 200
And the response should give us a reference UUID as `uuid`
When we send a GET request to /api/endpoint/`uuid`
Then the response code should be 200
...
所以问题是,我如何将我从第一次调用获得的 uuid 传达给后续步骤,并保持可重用的步骤,如通用 When we send a GET request to [parameter1]
我现在正在通过使用反引号定义变量来在 gherkin 中实现一种迷你语言,后续步骤应该能够访问这些变量。然而,这感觉像是有人已经以不同的方式解决了问题,或者被认为是不好的做法,因为我找不到其他人这样做的例子。
您可以查看 qaf webservice support. It provides request call repository 概念,您可以在请求调用中包含参数。
say {var-name} is value at jsonpath {jsonpath}
say {var-name} is value at xpath {xpath}
Feature: api-controller
Scenario: Adding
Given a live daemon
When user request "request.call1" with {"name": "foo"}
Then response should have status code 200
And say "UUID" is value at jsonpath "uuid"
When user request "request.call2"
Then response should have status code 200
...
这里的所有步骤都可以与 qaf webservice support 一起使用。在上面的示例中,它使用请求调用 request.call1
和 request.call2
,它们需要在属性文件或 xml 文件中定义。下面是 xml 文件中的示例。
<requests>
<request>
<call1>
<endPoint>/api/endpoint/</endPoint>
<headers>{'Content-Type': 'application/json'}</headers>
<method>POST</method>
<body>{'name': '${name}'}<body>
<parameters>
<!--default values of parameters if not provide-->
{
'name':'${rnd:aaa}'
}
</parameters>
</call1>
<call2>
<endPoint>/api/endpoint/${uuid}</endPoint>
<headers>{'Content-Type': 'application/json'}</headers>
<method>GET</method>
</call2>
</request>
</requests>
如果您想使用黄瓜,可以将其与 QAF-cucumber
一起使用
我遇到以下重复出现的问题,其模式如下:
Feature: api-controller
Scenario: Adding
Given a live daemon
When we send a POST request to /api/endpoint/ with data:
"""
{
"name": "foo",
}
"""
Then the response code should be 200
And the response should give us a reference UUID as `uuid`
When we send a GET request to /api/endpoint/`uuid`
Then the response code should be 200
...
所以问题是,我如何将我从第一次调用获得的 uuid 传达给后续步骤,并保持可重用的步骤,如通用 When we send a GET request to [parameter1]
我现在正在通过使用反引号定义变量来在 gherkin 中实现一种迷你语言,后续步骤应该能够访问这些变量。然而,这感觉像是有人已经以不同的方式解决了问题,或者被认为是不好的做法,因为我找不到其他人这样做的例子。
您可以查看 qaf webservice support. It provides request call repository 概念,您可以在请求调用中包含参数。
say {var-name} is value at jsonpath {jsonpath}
say {var-name} is value at xpath {xpath}
Feature: api-controller
Scenario: Adding
Given a live daemon
When user request "request.call1" with {"name": "foo"}
Then response should have status code 200
And say "UUID" is value at jsonpath "uuid"
When user request "request.call2"
Then response should have status code 200
...
这里的所有步骤都可以与 qaf webservice support 一起使用。在上面的示例中,它使用请求调用 request.call1
和 request.call2
,它们需要在属性文件或 xml 文件中定义。下面是 xml 文件中的示例。
<requests>
<request>
<call1>
<endPoint>/api/endpoint/</endPoint>
<headers>{'Content-Type': 'application/json'}</headers>
<method>POST</method>
<body>{'name': '${name}'}<body>
<parameters>
<!--default values of parameters if not provide-->
{
'name':'${rnd:aaa}'
}
</parameters>
</call1>
<call2>
<endPoint>/api/endpoint/${uuid}</endPoint>
<headers>{'Content-Type': 'application/json'}</headers>
<method>GET</method>
</call2>
</request>
</requests>
如果您想使用黄瓜,可以将其与 QAF-cucumber
一起使用