我设置了两个变量,假设在一个功能中 cityA = 'New York' 和 cityB = 'Las Vegas' 并将它们“导出”* def
表达。现在我想在另一个功能中使用这些变量
Scenario Outline: Successful transfer from <fromLocation> to <toLocation>
* call read('re-usable.feature')
Given request read('request.json')
When method post
Then status 200
Examples:
| fromLocation | toLocation |
| cityA | cityB |
| cityB | cityA |
有要求:
{
source: "#(fromLocation)"
destination: "#(toLocation)"
}
我的场景失败了,因为在请求中设置了 cityA/cityB,而不是存储在这些名称下的值,我尝试使用空手道配置文件中的变量,甚至
Scenario Outline: Successful transfer from <fromLocation> to <toLocation>
* def res = call read('re-usable.feature')
Given request read('request.json')
When method post
Then status 200
Examples:
| fromLocation | toLocation |
| res.cityA | res.cityB |
| res.cityB | res.cityA |
即传递“res.cityA”、“res.cityB”而不是纽约/拉斯维加斯
此外,我还尝试了以下方法
Background:
* call read('re-usable.feature')
Scenario Outline: Successful transfer from <fromLocation> to <toLocation>
Given request read('request.json')
When method post
Then status 200
Examples:
| fromLocation | toLocation |
| cityA | cityB |
| cityB | cityA |
and
Background:
* def res = call read('re-usable.feature')
Scenario Outline: Successful transfer from <fromLocation> to <toLocation>
Given request read('request.json')
When method post
Then status 200
Examples:
| fromLocation | toLocation |
| res.cityA | res.cityB |
| res.cityB | res.cityA |
所有呈现的情况都返回相同的变量名称而不是值。如果在请求中我设置了例如#(cityA)
代替#(toLocation)
那么一切都按预期进行,但在这种情况下我无法测试其他场景
@PeterThomas,您将我的最后一个问题标记为重复,但您提供的链接与我的问题无关;)