cygne
cygne

Reputation: 547

Can we call a scenario from one feature in another using karate?

We have a feature A with several scenarios. And we need one scenario from that file. Can we call it in our feature B?

Upvotes: 5

Views: 17397

Answers (2)

hc_dev
hc_dev

Reputation: 9418

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:

@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, e.g. 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

Upvotes: 1

Peter Thomas
Peter Thomas

Reputation: 58153

No. You need to extract that Scenario into a separate*.feature file and then re-use it using the call keyword.

EDIT: Karate 0.9.0 onwards will support being able to call by tag as follows:

* def result = call read('some.feature@tagname')

Upvotes: 9

Related Questions