简体   繁体   English

我们可以使用空手道从另一个功能中调用场景吗?

[英]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.

相关问题 如何使用空手道 API 测试将变量从一个特征文件调用到另一个特征文件 - How can I call a variable from one feature file to another feature file using Karate API Testing 我们可以在空手道的 afterScenario 中失败 Scenario/Scenario-Outline - Can we fail Scenario/Scenario-Outline from afterScenario in Karate 在从空手道中的另一个功能中调用场景时传递参数? - Passing parameters while calling a scenario from another feature flie in karate? 有没有办法从黄瓜特征文件场景中调用空手道的特征文件场景? - Is there a way to call Karate's feature file scenario from Cucumber feature files scenario? 我们可以在空手道特征文件中调用其他TestRunner文件吗 - Can we call other TestRunner file in the karate feature file 我可以使用空手道dsl将值从一个文件夹的一个功能文件传递到/ src / java / test下的另一个文件夹的另一个功能文件 - Can I pass values from one feature file of one folder to another feature file of another folder under /src/java/test using karate dsl 在一个功能中设置空手道中的全局变量以在另一功能中使用 - Setting global variables in karate from one feature to be used in another feature Karate-afterFeature - 主要特征文件不能使用 Karate-afterFeature 调用另一个特征文件 - Karate-afterFeature - main feature file cannot call another feature file using Karate-afterFeature 我们如何使用 Java API 在功能文件中使用 @tag 调用特定场景? - how can we call specific scenario with @tag in feature files using the Java API? 我们可以从 TestNG test Suit 运行空手道功能文件吗 - can we run karate feature file from TestNG test Suit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM