How to use call method of com.intuit.karate.core.ScenarioEngine class

Best Karate code snippet using com.intuit.karate.core.ScenarioEngine.call

Source:ScenarioBridge.java Github

copy

Full Screen

...135 }136 }137 return new JsList(list);138 }139 public Object call(String fileName) {140 return call(false, fileName, null);141 }142 public Object call(String fileName, Value arg) {143 return call(false, fileName, arg);144 }145 public Object call(boolean sharedScope, String fileName) {146 return call(sharedScope, fileName, null);147 }148 public Object call(boolean sharedScope, String fileName, Value arg) {149 ScenarioEngine engine = getEngine();150 Variable called = new Variable(engine.fileReader.readFile(fileName));151 Variable result = engine.call(called, arg == null ? null : new Variable(arg), sharedScope);152 return JsValue.fromJava(result.getValue());153 }154 private static Object callSingleResult(ScenarioEngine engine, Object o) throws Exception {155 if (o instanceof Exception) {156 engine.logger.warn("callSingle() cached result is an exception");157 throw (Exception) o;158 }159 // if we don't clone, an attach operation would update the tree within the cached value160 // causing future cache hit + attach attempts to fail !161 o = engine.recurseAndAttachAndShallowClone(o);162 return JsValue.fromJava(o);163 }164 public Object callSingle(String fileName) throws Exception {165 return callSingle(fileName, null);166 }167 public Object callSingle(String fileName, Value arg) throws Exception {168 ScenarioEngine engine = getEngine();169 final Map<String, Object> CACHE = engine.runtime.featureRuntime.suite.callSingleCache;170 int minutes = engine.getConfig().getCallSingleCacheMinutes();171 if ((minutes == 0) && CACHE.containsKey(fileName)) {172 engine.logger.trace("callSingle cache hit: {}", fileName);173 return callSingleResult(engine, CACHE.get(fileName));174 }175 long startTime = System.currentTimeMillis();176 engine.logger.trace("callSingle waiting for lock: {}", fileName);177 synchronized (CACHE) { // lock178 if ((minutes == 0) && CACHE.containsKey(fileName)) { // retry179 long endTime = System.currentTimeMillis() - startTime;180 engine.logger.warn("this thread waited {} milliseconds for callSingle lock: {}", endTime, fileName);181 return callSingleResult(engine, CACHE.get(fileName));182 }183 // this thread is the 'winner'184 engine.logger.info(">> lock acquired, begin callSingle: {}", fileName);185 Object result = null;186 File cacheFile = null;187 if (minutes > 0) {188 String cleanedName = StringUtils.toIdString(fileName);189 String cacheFileName = engine.getConfig().getCallSingleCacheDir() + File.separator + cleanedName + ".txt";190 cacheFile = new File(cacheFileName);191 long since = System.currentTimeMillis() - minutes * 60 * 1000;192 if (cacheFile.exists()) {193 long lastModified = cacheFile.lastModified();194 if (lastModified > since) {195 String json = FileUtils.toString(cacheFile);196 result = JsonUtils.fromJson(json);197 engine.logger.info("callSingleCache hit: {}", cacheFile);198 } else {199 engine.logger.info("callSingleCache stale, last modified {} - is before {} (minutes: {})",200 lastModified, since, minutes);201 }202 } else {203 engine.logger.info("callSingleCache file does not exist, will create: {}", cacheFile);204 }205 }206 if (result == null) {207 Variable called = new Variable(read(fileName));208 Variable argVar;209 if (arg == null || arg.isNull()) {210 argVar = null;211 } else {212 argVar = new Variable(arg);213 }214 Variable resultVar;215 try {216 resultVar = engine.call(called, argVar, false);217 } catch (Exception e) {218 // don't retain any vestiges of graal-js 219 RuntimeException re = new RuntimeException(e.getMessage());220 // we do this so that an exception is also "cached"221 resultVar = new Variable(re); // will be thrown at end222 engine.logger.warn("callSingle() will cache an exception");223 }224 if (minutes > 0) { // cacheFile will be not null225 if (resultVar.isMapOrList()) {226 String json = resultVar.getAsString();227 FileUtils.writeToFile(cacheFile, json);228 engine.logger.info("callSingleCache write: {}", cacheFile);229 } else {230 engine.logger.warn("callSingleCache write failed, not json-like: {}", resultVar);231 }232 }233 // functions have to be detached so that they can be re-hydrated in another js context234 result = engine.recurseAndDetachAndShallowClone(resultVar.getValue());235 }236 CACHE.put(fileName, result);237 engine.logger.info("<< lock released, cached callSingle: {}", fileName);238 return callSingleResult(engine, result);239 }240 }241 public Object callonce(String path) {242 return callonce(false, path);243 }244 public Object callonce(boolean sharedScope, String path) {245 String exp = "read('" + path + "')";246 Variable v = getEngine().call(true, exp, sharedScope);247 return JsValue.fromJava(v.getValue());248 }249 @Override250 public void capturePerfEvent(String name, long startTime, long endTime) {251 PerfEvent event = new PerfEvent(startTime, endTime, name, 200);252 getEngine().capturePerfEvent(event);253 }254 public void configure(String key, Value value) {255 getEngine().configure(key, new Variable(value));256 }257 public Object distinct(Value o) {258 if (!o.hasArrayElements()) {259 return JsList.EMPTY;260 }...

Full Screen

Full Screen

Source:ScenarioActions.java Github

copy

Full Screen

...298 public void remove(String name, String path) {299 engine.remove(name, path);300 }301 @Override302 @When("^call (.+)")303 public void call(String line) {304 engine.call(false, line, true);305 }306 @Override307 @When("^callonce (.+)")308 public void callonce(String line) {309 engine.call(true, line, true);310 }311 @Override312 @When("^eval (.+)")313 public Object eval(String exp) {314 return engine.evalJs(exp).getValue();315 }316 @Override317 @When("^eval$")318 public Object evalDocstring(String exp) {319 return engine.evalJs(exp).getValue();320 }321 @Override322 @When("^([\\w]+)([^\\s^\\w])(.+)")323 public Object eval(String name, String dotOrParen, String exp) {...

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.core.ScenarioEngine;2import com.intuit.karate.core.ScenarioRuntime;3import com.intuit.karate.core.FeatureRuntime;4import com.intuit.karate.core.Feature;5import com.intuit.karate.core.FeatureParser;6import com.intuit.karate.core.FeatureContext;7import com.intuit.karate.core.FeatureResult;8import java.io.File;9import java.util.Map;10import java.util.HashMap;11import java.util.List;12import java.util.ArrayList;13import java.util.Arrays;14import java.util.Collection;15import java.util.Set;16import java.util.HashSet;17import java.util.Iterator;18import java.util.Collections;19import java.util.LinkedHashMap;20import java.util.concurrent.atomic.AtomicInteger;21import java.util.concurrent.atomic.AtomicBoolean;22import java.util.concurrent.ExecutorService;23import java.util.concurrent.Executors;24import java.util.concurrent.TimeUnit;25import java.util.concurrent.Callable;26import java.util.concurrent.Future;27import java.util.concurrent.ExecutionException;28import java.util.concurrent.TimeoutException;29import java.util.concurrent.ConcurrentHashMap;30import java.util.concurrent.ConcurrentMap;31import java.util.concurrent.ConcurrentHashMap;32import java.util.concurrent.ConcurrentMap;33import com.intuit.karate.core.ScenarioResult;34import com.intuit.karate.core.ScenarioContext;35import com.intuit.karate.core.Scenario;36import com.intuit.karate.core.Feature;37import com.intuit.karate.core.FeatureContext;38import com.intuit.karate.core.FeatureParser;39import com.intuit.karate.core.FeatureResult;40import com.intuit.karate.core.FeatureRuntime;41import com.intuit.karate.core.ScenarioRuntime;42import com.intuit.karate.core.ScenarioEngine;43import com.intuit.karate.core.ScenarioContext;44import com.intuit.karate.core.ScenarioResult;45import com.intuit.karate.core.Scenario;46import com.intuit.karate.core.FeatureContext;47import com.intuit.karate.core.FeatureResult;48import com.intuit.karate.core.FeatureRuntime;49import com.intuit.karate.core.Feature;50import com.intuit.karate.core.FeatureParser;51import com.intuit.karate.core.FeatureContext;52import com.intuit.karate.core.FeatureResult;53import com.intuit.karate.core.FeatureRuntime;54import com.intuit.karate.core.Feature;55import com.intuit.karate.core.FeatureParser;56import com.intuit.karate.core.FeatureContext;57import

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.core.ScenarioEngine;2import com.intuit.karate.core.ScenarioResult;3import com.intuit.karate.core.ScenarioContext;4import com.intuit.karate.core.Feature;5import java.util.Map;6import java.util.HashMap;7import java.util.List;8import java.util.ArrayList;9import java.util.concurrent.Future;10import java.util.concurrent.TimeUnit;11import java.util.concurrent.TimeoutException;12import java.util.concurrent.ExecutionException;13import java.util.concurrent.Callable;14import java.util.concurrent.ExecutorService;15import java.util.concurrent.Executors;16import java.util.concurrent.Future;17import java.util.concurrent.TimeUnit;18import java.util.concurrent.TimeoutException;19import java.util.concurrent.ExecutionException;20import java.util.concurrent.Callable;21import java.util.concurrent.ExecutorService;22import java.util.concurrent.Executors;23import java.util.concurrent.Future;24import java.util.concurrent.TimeUnit;25import java.util.concurrent.TimeoutException;26import java.util.concurrent.ExecutionException;27import java.util.concurrent.Callable;28import java.util.concurrent.ExecutorService;29import java.util.concurrent.Executors;30import java.util.concurrent.Future;31import java.util.concurrent.TimeUnit;32import java.util.concurrent.TimeoutException;33import java.util.concurrent.ExecutionException;34import java.util.concurrent.Callable;35import java.util.concurrent.ExecutorService;36import java.util.concurrent.Executors;37import java.util.concurrent.Future;38import java.util.concurrent.TimeUnit;39import java.util.concurrent.TimeoutException;40import java.util.concurrent.ExecutionException;41import java.util.concurrent.Callable;42import java.util.concurrent.ExecutorService;43import java.util.concurrent.Executors;44import java.util.concurrent.Future;45import java.util.concurrent.TimeUnit;46import java.util.concurrent.TimeoutException;47import java.util.concurrent.ExecutionException;48import java.util.concurrent.Callable;49import java.util.concurrent.ExecutorService;50import java.util.concurrent.Executors;51import java.util.concurrent.Future;52import java.util.concurrent.TimeUnit;53import java.util.concurrent.TimeoutException;54import java.util.concurrent.ExecutionException;55import java.util.concurrent.Callable;56import java.util.concurrent.ExecutorService;57import java.util.concurrent.Executors;58import java.util.concurrent.Future;59import java.util.concurrent.TimeUnit;60import java.util.concurrent.TimeoutException;61import java.util.concurrent.ExecutionException;62import java.util.concurrent.Callable;63import java.util.concurrent.ExecutorService;64import java.util.concurrent.Executors;65import java.util.concurrent.Future;66import java.util.concurrent.TimeUnit;67import java.util.concurrent.TimeoutException;68import java.util.concurrent.ExecutionException;69import java.util.concurrent.Callable;70import java.util.concurrent.ExecutorService;71import java.util.concurrent.Executors;72import java.util.concurrent.Future;73import java.util

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.core.ScenarioEngine;2import com.intuit.karate.core.ScenarioResult;3import java.util.HashMap;4import java.util.Map;5public class CallMethodDemo {6 public static void main(String[] args) {7 ScenarioEngine engine = ScenarioEngine.create();8 Map<String, Object> vars = new HashMap<>();9 vars.put("name", "karate");10 ScenarioResult result = engine.call("classpath:call.feature", vars);11 System.out.println(result);12 }13}

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.core.ScenarioEngine;2import com.intuit.karate.core.ScenarioResult;3import com.intuit.karate.core.ScenarioRuntime;4import com.intuit.karate.core.ScenarioContext;5import com.intuit.karate.core.Scenario;6import com.intuit.karate.core.Feature;7import com.intuit.karate.core.FeatureRuntime;8import com.intuit.karate.core.FeatureContext;9import com.intuit.karate.core.FeatureResult;10import com.intuit.karate.core.FeatureInfo;11import com.intuit.karate.core.Feature;12import com.intuit.karate.core.FeatureRuntime;13import com.intuit.karate.core.FeatureContext;14import com.intuit.karate.core.FeatureResult;15import com.intuit.karate.core.FeatureInfo;16import com.intuit.karate.core.Feature;17import com.intuit.karate.core.FeatureRuntime;18import com.intuit.karate.core.FeatureContext;19import com.intuit.karate.core.FeatureResult;20import com.intuit.karate.core.FeatureInfo;21import com.intuit.karate.core.Feature;22import com.intuit.karate.core.FeatureRuntime;23import com.intuit.karate.core.FeatureContext;24import com.intuit.karate.core.FeatureResult;25import com.intuit.karate.core.FeatureInfo;26import com.intuit.karate.core.Feature;27import com.intuit.karate.core.FeatureRuntime;28import com.intuit.karate.core.FeatureContext;29import com.intuit.karate.core.FeatureResult;30import com.intuit.karate.core.FeatureInfo;31import com.intuit.karate.core.Feature;32import com.intuit.karate.core.FeatureRuntime;33import com.intuit.karate.core.FeatureContext;34import com.intuit.karate.core.FeatureResult;35import com.intuit.karate.core.FeatureInfo;36import com.intuit.karate.core.Feature;37import com.intuit.karate.core.FeatureRuntime;38import com.intuit.karate.core.FeatureContext;39import com.intuit.karate.core.FeatureResult;40import com.intuit.karate.core.FeatureInfo;41import com.intuit.karate.core.Feature;42import com.intuit.karate.core.FeatureRuntime;43import com.intuit.karate.core.FeatureContext;44import com.intuit.karate.core.FeatureResult;45import com.intuit.karate.core

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.core.ScenarioEngine;2import com.intuit.karate.core.ScenarioResult;3import java.io.File;4import java.util.Map;5public class CallFeatureFile {6 public static void main(String[] args) {7 ScenarioEngine engine = new ScenarioEngine();8 File file = new File("src/test/java/com/intuit/karate/demo/demo.feature");9 ScenarioResult result = engine.call(file, null, null);10 Map<String, Object> vars = result.getVars();11 System.out.println("vars = " + vars);12 }13}14import com.intuit.karate.core.ScenarioEngine;15import com.intuit.karate.core.ScenarioResult;16import java.io.File;17import java.util.HashMap;18import java.util.Map;19public class CallFeatureFile {20 public static void main(String[] args) {21 ScenarioEngine engine = new ScenarioEngine();22 File file = new File("src/test/java/com/intuit/karate/demo/demo.feature");23 Map<String, Object> vars = new HashMap();24 vars.put("foo", "bar");25 ScenarioResult result = engine.call(file, vars, null);26 System.out.println("vars = " + result.getVars());27 }28}29import com.intuit.karate.core.ScenarioEngine;30import com.intuit.karate.core.ScenarioResult;31import java.io.File;32import java.util.HashMap;33import java.util.Map;34public class CallFeatureFile {35 public static void main(String[] args) {36 ScenarioEngine engine = new ScenarioEngine();37 File file = new File("src/test/java/com/intuit/karate/demo/demo.feature");38 Map<String, Object> vars = new HashMap();39 vars.put("foo", "bar");40 vars.put("hello", (Function) (args) -> {41 return "world";42 });43 ScenarioResult result = engine.call(file, vars, null);44 System.out.println("vars = " + result.getVars());45 }46}

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1package com.intuit.karate;2import java.io.File;3import java.io.IOException;4import org.apache.commons.io.FileUtils;5import org.junit.Test;6import com.intuit.karate.core.ScenarioEngine;7public class 4 {8public void testParallel() throws IOException {9File file = new File("target/surefire-reports");10FileUtils.deleteDirectory(file);11ScenarioEngine engine = ScenarioEngine.instance;12engine.setReportDir("target/surefire-reports");13engine.setLogLevel("INFO");14engine.setParallel(1);15engine.setConfigFile("classpath:karate-config.js");16engine.setFeatureFiles("classpath:4.feature");17engine.run();18}19}20function fn() {21var config = {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Karate automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ScenarioEngine

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful