[英]Can we call a scenario from one feature in another using karate?
We have a feature A with several scenarios.我们有一个具有多种场景的特征 A。 And we need one scenario from that file.我们需要该文件中的一个场景。 Can we call it in our feature B?我们可以在我们的功能 B 中调用它吗?
No. You need to extract that Scenario into a separate *.feature
file and then re-use it using the call
keyword. *.feature
。您需要将该场景提取到单独的*.feature
文件中,然后使用call
关键字重新使用它。
EDIT: Karate 0.9.0 onwards will support being able to call by tag as follows:编辑:空手道 0.9.0 以后将支持能够按标签调用,如下所示:
* def result = call read('some.feature@tagname')
I have a concern with this approach: Karate should allow re-usability from a feature file itself for a particular scenario. 我对这种方法感到担心:空手道应该允许特定情况下功能文件本身的可重用性。
If I have such numerous cases then i will end up with a lot of feature files which would be holding duplicate scenarios just for the sake of getting called. 如果我遇到如此多的情况,那么我最终会得到很多功能文件,这些功能文件只是为了被调用而持有重复的场景。
To illustrate the answer from Karate-inventor Peter Thomas with an example:举一个例子来说明空手道发明者彼得·托马斯的回答:
Given a feature-file some.feature
with multiple scenarios tagged by a tag-decorator :给定一个特征文件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
In another feature we can call a specific scenario from that feature by its tag, eg tagname
:在另一个特性中,我们可以通过它的标签调用该特性的特定场景,例如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'
See also: demo of adding custom tags to scenarios另请参阅: 向场景添加自定义标签的演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.