Karate - callonce feature doesn't cache the response

Viewed 1703

I have two feature files and I'm trying to reuse the result of the first feature file as a background to the second feature file's scenario

Feature file 1

Feature: First feature file Scenario: create random session id * def sessionId = Java.type('com.company.RandomSessionId').getRandomSessionId()

Feature file 2

Feature: calling another feature file Background: * def mycall = callonce read('first.feature') * def randomId = mycall.sessionId

Scenario: print sessionId * print randomId Scenario: print sessionId-2 * print randomId

When I execute the scenarios in Feature file 2, I get two different results.

1 Answers

It must be because you are using the IDE support / right-click / "run-as" option. This is an open issue, because Karate needs to cache across Scenarios which "native" Cucumber does not support: https://github.com/intuit/karate/issues/136 - apologies and I need to update the documentation.

Please use a JUnit runner for these cases, I recommend having these in place for dev-mode anyway, and the new HTML dev-mode report makes this even more useful: https://twitter.com/KarateDSL/status/935029435140489216

Related