How to use getDebugInfo method of com.intuit.karate.core.Scenario class

Best Karate code snippet using com.intuit.karate.core.Scenario.getDebugInfo

Source:ScenarioRuntime.java Github

copy

Full Screen

...240 return info;241 }242 protected void logError(String message) {243 if (currentStep != null) {244 message = currentStep.getDebugInfo()245 + "\n" + currentStep.toString()246 + "\n" + message;247 }248 logger.error("{}", message);249 }250 private Map<String, Object> initMagicVariables() {251 Map<String, Object> map = new HashMap();252 if (!caller.isNone()) {253 // karate principle: parent variables are always "visible"254 // so we inject the parent variables255 // but they will be over-written by what is local to this scenario256 if (caller.isSharedScope()) {257 map.putAll(caller.parentRuntime.magicVariables);258 } else {259 // the shallow clone of variables is important260 // otherwise graal / js functions in calling context get corrupted261 caller.parentRuntime.engine.vars.forEach((k, v) -> map.put(k, v == null ? null : v.copy(false).getValue()));262 // shallow copy magicVariables263 map.putAll((Map<String, Object>) caller.parentRuntime.engine.shallowClone(caller.parentRuntime.magicVariables));264 }265 map.put("__arg", caller.arg == null ? null : caller.arg.getValue());266 map.put("__loop", caller.getLoopIndex());267 }268 if (scenario.isOutlineExample() && !this.isDynamicBackground()) { // init examples row magic variables269 Map<String, Object> exampleData = scenario.getExampleData();270 map.putAll(exampleData);271 map.put("__row", exampleData);272 map.put("__num", scenario.getExampleIndex());273 }274 return map;275 }276 private void evalConfigJs(String js, String displayName) {277 if (js == null || configFailed) {278 return;279 }280 try {281 Variable fun = engine.evalJs("(" + js + ")");282 if (!fun.isJsFunction()) {283 logger.warn("not a valid js function: {}", displayName);284 return;285 }286 Map<String, Object> map = engine.getOrEvalAsMap(fun);287 engine.setVariables(map);288 } catch (Exception e) {289 String message = ">> " + scenario.getDebugInfo() + "\n>> " + displayName + " failed\n>> " + e.getMessage();290 error = JsEngine.fromJsEvalException(js, e, message);291 stopped = true;292 configFailed = true;293 }294 }295 private static boolean isSelectedForExecution(FeatureRuntime fr, Scenario scenario, Tags tags) {296 Feature feature = scenario.getFeature();297 int callLine = feature.getCallLine();298 if (callLine != -1) {299 int sectionLine = scenario.getSection().getLine();300 int scenarioLine = scenario.getLine();301 if (callLine == sectionLine || callLine == scenarioLine) {302 fr.logger.info("found scenario at line: {}", callLine);303 return true;304 }305 fr.logger.trace("skipping scenario at line: {}, needed: {}", scenario.getLine(), callLine);306 return false;307 }308 String callName = feature.getCallName();309 if (callName != null) {310 if (scenario.getName().matches(callName)) {311 fr.logger.info("found scenario at line: {} - {}", scenario.getLine(), callName);312 return true;313 }314 fr.logger.trace("skipping scenario at line: {} - {}, needed: {}", scenario.getLine(), scenario.getName(), callName);315 return false;316 }317 String callTag = feature.getCallTag();318 if (callTag != null && (!fr.caller.isNone() || fr.perfHook != null)) {319 // only if this is a legit "call" or a gatling "call by tag"320 if (tags.contains(callTag)) {321 fr.logger.info("{} - call by tag at line {}: {}", fr, scenario.getLine(), callTag);322 return true;323 }324 fr.logger.trace("skipping scenario at line: {} with call by tag effective: {}", scenario.getLine(), callTag);325 return false;326 }327 if (fr.caller.isNone()) {328 if (tags.evaluate(fr.suite.tagSelector, fr.suite.env)) {329 fr.logger.trace("matched scenario at line: {} with tags effective: {}", scenario.getLine(), tags.getTags());330 return true;331 }332 fr.logger.trace("skipping scenario at line: {} with tags effective: {}", scenario.getLine(), tags.getTags());333 return false;334 } else {335 return true; // when called, tags are ignored, all scenarios will be run336 }337 }338 //==========================================================================339 //340 public void beforeRun() {341 if (isDynamicBackground()) {342 steps = scenario.getBackgroundSteps();343 } else {344 steps = background == null ? scenario.getStepsIncludingBackground() : scenario.getSteps();345 }346 ScenarioEngine.set(engine);347 engine.init();348 engine.getConfig().attach(engine.JS);349 if (this.background != null) {350 ScenarioEngine backgroundEngine = background.engine;351 if (backgroundEngine.driver != null) {352 engine.setDriver(backgroundEngine.driver);353 }354 if (backgroundEngine.robot != null) {355 engine.setRobot(backgroundEngine.robot);356 }357 }358 result.setExecutorName(Thread.currentThread().getName());359 result.setStartTime(System.currentTimeMillis());360 if (!dryRun) {361 if (caller.isNone() && !caller.isKarateConfigDisabled()) {362 // evaluate config js, variables above will apply !363 evalConfigJs(featureRuntime.suite.karateBase, "karate-base.js");364 evalConfigJs(featureRuntime.suite.karateConfig, "karate-config.js");365 evalConfigJs(featureRuntime.suite.karateConfigEnv, "karate-config-" + featureRuntime.suite.env + ".js");366 }367 if (isDynamicBackground()) {368 featureRuntime.suite.hooks.forEach(h -> h.beforeBackground(this));369 if (featureRuntime.suite.debugMode) {370 skipped = !featureRuntime.suite.hooks.stream()371 .filter(DebugThread.class::isInstance)372 .map(h -> h.beforeScenario(this))373 .reduce(Boolean.TRUE, Boolean::logicalAnd);374 }375 } else {376 skipped = !featureRuntime.suite.hooks.stream()377 .map(h -> h.beforeScenario(this))378 .reduce(Boolean.TRUE, Boolean::logicalAnd);379 }380 if (skipped) {381 logger.debug("beforeScenario hook returned false, will skip scenario: {}", scenario);382 }383 }384 if (!skipped && !isDynamicBackground()) {385 // don't evaluate names when running the background section386 evaluateScenarioName();387 }388 }389 @Override390 public void run() {391 boolean reRun = false;392 try { // make sure we call afterRun() even on crashes393 // and operate countdown latches, else we may hang the parallel runner394 if (steps == null) {395 beforeRun();396 }397 if (skipped) {398 return;399 }400 int count = steps.size();401 int index = 0;402 reRun = stepIndex >= count;403 while ((index = nextStepIndex()) < count) {404 currentStep = steps.get(index);405 execute(currentStep);406 if (currentStepResult != null) { // can be null if debug step-back or hook skip407 result.addStepResult(currentStepResult);408 }409 }410 } catch (Exception e) {411 if (currentStepResult != null) {412 result.addStepResult(currentStepResult);413 }414 logError("scenario [run] failed\n" + StringUtils.throwableToString(e));415 currentStepResult = result.addFakeStepResult("scenario [run] failed", e);416 } finally {417 if (isDynamicBackground() && !reRun && !skipped) {418 featureRuntime.suite.hooks.forEach(h -> h.afterBackground(this));419 // if it's a dynamic scenario running under the debugger420 // we still want to execute the afterScenario() hook of the debugger server421 // in the background section422 if (featureRuntime.suite.debugMode) {423 // allow debugging background section424 featureRuntime.suite.hooks.stream()425 .filter(DebugThread.class::isInstance)426 .forEach(h -> h.afterScenario(this));427 }428 } else if (!isDynamicBackground() && !skipped) { // don't add "fake" scenario to feature results429 afterRun();430 }431 if (caller.isNone()) {432 logAppender.close(); // reclaim memory433 }434 }435 }436 public StepResult execute(Step step) {437 if (!stopped && !dryRun) {438 boolean shouldExecute = true;439 for (RuntimeHook hook : featureRuntime.suite.hooks) {440 if (!hook.beforeStep(step, this)) {441 shouldExecute = false;442 }443 }444 if (!shouldExecute) {445 return null;446 }447 }448 Result stepResult;449 final boolean executed = !stopped;450 if (stopped) {451 if (aborted && engine.getConfig().isAbortedStepsShouldPass()) {452 stepResult = Result.passed(0);453 } else if (configFailed) {454 stepResult = Result.failed(0, error, step);455 } else {456 stepResult = Result.skipped();457 }458 } else if (dryRun) {459 stepResult = Result.passed(0);460 } else {461 stepResult = StepRuntime.execute(step, actions);462 }463 currentStepResult = new StepResult(step, stepResult);464 if (stepResult.isAborted()) { // we log only aborts for visibility465 aborted = true;466 stopped = true;467 logger.debug("abort at {}", step.getDebugInfo());468 } else if (stepResult.isFailed()) {469 if (stepResult.getMatchingMethod() != null && this.engine.getConfig().getContinueOnStepFailureMethods().contains(stepResult.getMatchingMethod().method)) {470 stopped = false;471 ignoringFailureSteps = true;472 currentStepResult.setErrorIgnored(true);473 } else {474 stopped = true;475 }476 if (stopped && (!this.engine.getConfig().isContinueAfterContinueOnStepFailure() || !this.engine.isIgnoringStepErrors())) {477 error = stepResult.getError();478 logError(error.getMessage());479 }480 } else {481 boolean hidden = reportDisabled || (step.isPrefixStar() && !step.isPrint() && !engine.getConfig().isShowAllSteps());...

Full Screen

Full Screen

Source:Step.java Github

copy

Full Screen

...61 this.text = tempStep.text;62 this.docString = tempStep.docString;63 this.table = tempStep.table;64 }65 public String getDebugInfo() {66 return feature + ":" + line;67 }68 public boolean isPrint() {69 return text != null && text.startsWith("print");70 }71 public boolean isPrefixStar() {72 return "*".equals(prefix);73 }74 public Feature getFeature() {75 return feature;76 }77 public Step(Feature feature, int index) {78 this.feature = feature;79 this.scenario = null;...

Full Screen

Full Screen

getDebugInfo

Using AI Code Generation

copy

Full Screen

1package demo;2import com.intuit.karate.FileUtils;3import com.intuit.karate.core.Scenario;4import com.intuit.karate.core.ScenarioResult;5import com.intuit.karate.core.ScenarioRuntime;6import java.io.File;7import java.util.Map;8public class Demo {9 public static void main(String[] args) {10 File file = FileUtils.getFileRelativeTo(Demo.class, "demo.feature");11 Scenario scenario = Scenario.read(file, null);12 ScenarioRuntime runtime = scenario.getRuntime();13 ScenarioResult result = runtime.run(null);14 System.out.println("result = " + result);15 Map<String, Object> debugInfo = runtime.getDebugInfo();16 System.out.println("debugInfo = " + debugInfo);17 }18}19package demo;20import com.intuit.karate.FileUtils;21import com.intuit.karate.core.Scenario;22import com.intuit.karate.core.ScenarioResult;23import com.intuit.karate.core.ScenarioRuntime;24import java.io.File;25import java.util.Map;26public class Demo {27 public static void main(String[] args) {28 File file = FileUtils.getFileRelativeTo(Demo.class, "demo.feature");29 Scenario scenario = Scenario.read(file, null);30 ScenarioRuntime runtime = scenario.getRuntime();31 ScenarioResult result = runtime.run(null);32 System.out.println("result = " + result);33 Map<String, Object> debugInfo = runtime.getDebugInfo();34 System.out.println("debugInfo = " + debugInfo);35 }36}37package demo;38import com.intuit.karate.FileUtils;39import com.intuit.karate.core.Scenario;40import com.intuit.karate.core.ScenarioResult;41import com.intuit.karate.core.ScenarioRuntime;42import java.io.File;43import java.util.Map;44public class Demo {45 public static void main(String[] args) {46 File file = FileUtils.getFileRelativeTo(Demo.class, "demo.feature");47 Scenario scenario = Scenario.read(file, null);48 ScenarioRuntime runtime = scenario.getRuntime();49 ScenarioResult result = runtime.run(null);50 System.out.println("result = " + result);

Full Screen

Full Screen

getDebugInfo

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.*;2import java.io.*;3import java.util.*;4public class 4 {5 public static void main(String[] args) {6 String env = System.getProperty("karate.env");7 if (env == null) {8 env = "dev";9 }10 String feature = "classpath:features/1.feature";11 Scenario scenario = Scenario.read(feature, env);12 List<String> debugInfo = scenario.getDebugInfo();13 try {14 PrintWriter writer = new PrintWriter("debug.txt", "UTF-8");15 for (String line : debugInfo) {16 writer.println(line);17 }18 writer.close();19 } catch (Exception e) {20 e.printStackTrace();21 }22 }23}

Full Screen

Full Screen

getDebugInfo

Using AI Code Generation

copy

Full Screen

1package com.intuit.karate.core;2import com.intuit.karate.FileUtils;3import com.intuit.karate.JsonUtils;4import com.intuit.karate.core.Scenario;5import com.intuit.karate.core.ScenarioResult;6import com.intuit.karate.core.ScenarioRuntime;7import com.intuit.karate.core.ScenarioUtils;8import com.intuit.karate.core.StepResult;9import com.intuit.karate.core.StepRuntime;10import java.io.File;11import java.util.List;12import java.util.Map;13import java.util.HashMap;14import java.util.ArrayList;15import java.util.Arrays;16import java.util.Collections;17import java.util.LinkedHashMap;18import java.util.Map;19import java.util.stream.Collectors;20import org.slf4j.Logger;21import org.slf4j.LoggerFactory;22public class DebugInfo {23 private static final Logger logger = LoggerFactory.getLogger(DebugInfo.class);24 public static void main(String[] args) {25 String feature = FileUtils.toString(new File("src/test/java/com/intuit/karate/core/4.feature"));26 String scenarioName = "Scenario 1";27 Scenario scenario = ScenarioUtils.parseScenario(feature, scenarioName, null, null);28 ScenarioRuntime runtime = new ScenarioRuntime(scenario, null);29 ScenarioResult result = runtime.run();30 Map<String,Object> debugInfo = result.getDebugInfo();31 System.out.println(JsonUtils.toJsonPretty(debugInfo));32 }33}34package com.intuit.karate.core;35import com.intuit.karate.FileUtils;36import com.intuit.karate.JsonUtils;37import com.intuit.karate.core.Scenario;38import com.intuit.karate.core.ScenarioResult;39import com.intuit.kar

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful