diff --git a/karate-core/src/main/java/com/intuit/karate/core/ScenarioRuntime.java b/karate-core/src/main/java/com/intuit/karate/core/ScenarioRuntime.java index 81c0254d6..416294726 100644 --- a/karate-core/src/main/java/com/intuit/karate/core/ScenarioRuntime.java +++ b/karate-core/src/main/java/com/intuit/karate/core/ScenarioRuntime.java @@ -38,7 +38,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Semaphore; -import java.util.concurrent.locks.ReentrantLock; /** * @@ -88,11 +87,13 @@ public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario, Scenari logger.setAppender(logAppender); actions = new ScenarioActions(engine); this.scenario = scenario; - magicVariables = initMagicVariables(background); // depends on scenario this.background = background; // used only to check which steps remain + magicVariables = initMagicVariables(); result = new ScenarioResult(scenario); if (background != null) { result.addStepResults(background.result.getStepResults()); + Map detached = background.engine.detachVariables(); + engine.vars.putAll(detached); } dryRun = featureRuntime.suite.dryRun; tags = scenario.getTagsEffective(); @@ -243,14 +244,8 @@ protected void logError(String message) { logger.error("{}", message); } - private Map initMagicVariables(ScenarioRuntime background) { + private Map initMagicVariables() { Map map = new HashMap(); - if (background != null) { - // detaching is as good as cloning - // the detach is needed as the js-engine will be different - Map detached = background.engine.detachVariables(); - detached.forEach((k, v) -> map.put(k, v.getValue())); - } if (caller.isNone()) { // if feature called via java api if (caller.arg != null && caller.arg.isMap()) { map.putAll(caller.arg.getValue());