Karate 在带有列表的场景大纲中使用条件逻辑
我们使用空手道0.9.5。我们想使用条件逻辑来制作一个动态场景大纲。 我们希望检索区域列表中的城镇,这是国家列表中的城镇。 条件逻辑仅在检索中使用。我们所做的: 主要特点:Karate 在带有列表的场景大纲中使用条件逻辑,karate,Karate,我们使用空手道0.9.5。我们想使用条件逻辑来制作一个动态场景大纲。 我们希望检索区域列表中的城镇,这是国家列表中的城镇。 条件逻辑仅在检索中使用。我们所做的: 主要特点: Scenario Outline: * def countries = call read('GetRegionsWithTowns.feature') { countryId: '#(<id>)' } Examples: |countriesList| GetTowns.feature Scenario:
Scenario Outline:
* def countries = call read('GetRegionsWithTowns.feature') { countryId: '#(<id>)' }
Examples:
|countriesList|
GetTowns.feature
Scenario:
Given url 'someurl'
And path countryId, 'regions'
When method get
Then status 200
Scenario:
Given url 'someurl'
And path regionId, 'towns'
When method get
Then status 200
错误是
GetTowns.feature:16 (the line with "And path regionId, 'towns'") - javascript evaluation failed: regionId, ReferenceError: "regionId" is not defined in <eval> at line number 1
GetTowns.feature:16(带有“And path regionId,'towns'”的行)-javascript计算失败:regionId,ReferenceError:“regionId”未在第1行中定义
我们不知道我们做错了什么?欢迎任何帮助,谢谢我想这就是需要的改变:
karate.call('GetTowns.feature', { regionId: regionId });
我确实认为你的测试过于复杂了
- 我会尽量避免打电话
- 父要素中定义的任何变量都将对“调用”要素可见,因此您不需要将所有数据作为参数传递
- 尽量避免使用JS代码,尤其是循环,请参阅:
karate.call('GetTowns.feature', { regionId: regionId });