【发布时间】:2017-09-22 19:43:30
【问题描述】:
我们有一个包含多个场景的功能 A。我们需要该文件中的一个场景。我们可以在功能 B 中调用它吗?
【问题讨论】:
-
我对这种方法有一点担忧:空手道应该允许在特定场景下从功能文件本身重用。如果我有这么多的案例,那么我最终会得到很多功能文件,这些文件会保留重复的场景,只是为了被调用。
标签: karate
我们有一个包含多个场景的功能 A。我们需要该文件中的一个场景。我们可以在功能 B 中调用它吗?
【问题讨论】:
标签: karate
没有。您需要将该场景提取到单独的*.feature 文件中,然后使用call 关键字重新使用它。
编辑:空手道 0.9.0 及以后的版本将支持按标签调用,如下所示:
* def result = call read('some.feature@tagname')
【讨论】:
用一个例子来说明answer from Karate-inventor Peter Thomas:
给定一个特征文件some.feature,其中有多个场景标记tag-decorator:
@tagname
Scenario: A, base case that shares results to e.g. B
// given, when, then ... and share result in a map with keyword `uri`
* def uri = responseHeaders['Location'][0]
@anotherTag
Scenario: X, base case that shares results to e.g. B
// given, when, then ... and share result in a map with keyword `createdResourceId`
* def createdResourceId = $.id
在另一个特性中,我们可以通过它的标签从那个特性中调用一个特定的 scenario,例如tagname:
Scenario: B, another case reusing some results of A
* def result = call read('some.feature@tagname')
* print "given result of A is: $result"
Given path result.uri + '/update'
【讨论】: