Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright 2020 Intuit Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.intuit.karate.core;
import com.intuit.karate.FileUtils;
import com.intuit.karate.KarateException;
import com.intuit.karate.LogAppender;
import com.intuit.karate.Logger;
import com.intuit.karate.RuntimeHook;
import com.intuit.karate.ScenarioActions;
import com.intuit.karate.debug.DebugThread;
import com.intuit.karate.http.ResourceType;
import com.intuit.karate.shell.StringLogAppender;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Semaphore;
/**
* @author pthomas3
*/
public class ScenarioRuntime implements Runnable {
public final Logger logger;
public final FeatureRuntime featureRuntime;
public final ScenarioRuntime background;
public final ScenarioCall caller;
public final Scenario scenario;
public final Tags tags;
public final ScenarioActions actions;
public final ScenarioResult result;
public final ScenarioEngine engine;
public final boolean reportDisabled;
public final Map magicVariables;
public final boolean selectedForExecution;
public final boolean perfMode;
public final boolean dryRun;
public final LogAppender logAppender;
public boolean ignoringFailureSteps;
public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario) {
this(featureRuntime, scenario, null);
}
public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario, ScenarioRuntime background) {
logger = new Logger();
this.featureRuntime = featureRuntime;
this.caller = featureRuntime.caller;
perfMode = featureRuntime.perfHook != null;
if (caller.isNone()) {
logAppender = perfMode ? LogAppender.NO_OP : new StringLogAppender(false);
engine = new ScenarioEngine(new Config(), this, new HashMap(), logger);
} else if (caller.isSharedScope()) {
logAppender = caller.parentRuntime.logAppender;
Config config = caller.parentRuntime.engine.getConfig();
Map vars = caller.parentRuntime.engine.vars;
engine = new ScenarioEngine(config, this, vars, logger);
} else { // new, but clone and copy data
logAppender = caller.parentRuntime.logAppender;
Config config = new Config(caller.parentRuntime.engine.getConfig());
Map vars = caller.parentRuntime.engine.copyVariables(false);
engine = new ScenarioEngine(config, this, vars, logger);
}
logger.setAppender(logAppender);
actions = new ScenarioActions(engine);
this.scenario = 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(true);
detached.forEach((k, v) -> engine.vars.put(k, v));
engine.requestBuilder = background.engine.requestBuilder.copy();
}
dryRun = featureRuntime.suite.dryRun;
tags = scenario.getTagsEffective();
reportDisabled = perfMode ? true : tags.valuesFor("report").isAnyOf("false");
selectedForExecution = isSelectedForExecution(featureRuntime, scenario, tags);
}
public boolean isFailed() {
return error != null || result.isFailed();
}
public boolean isIgnoringFailureSteps() {
return ignoringFailureSteps;
}
public Step getCurrentStep() {
return currentStep;
}
public boolean isStopped() {
return stopped;
}
public boolean isDynamicBackground() {
return this.scenario.isDynamic() && this.background == null;
}
public String getEmbedFileName(ResourceType resourceType) {
String extension = resourceType == null ? null : resourceType.getExtension();
return scenario.getUniqueId() + "_" + System.currentTimeMillis() + (extension == null ? "" : "." + extension);
}
public Embed saveToFileAndCreateEmbed(byte[] bytes, ResourceType resourceType) {
File file = new File(featureRuntime.suite.reportDir + File.separator + getEmbedFileName(resourceType));
FileUtils.writeToFile(file, bytes);
return new Embed(file, resourceType);
}
public Embed embed(byte[] bytes, ResourceType resourceType) {
if (embeds == null) {
embeds = new ArrayList();
}
Embed embed = saveToFileAndCreateEmbed(bytes, resourceType);
embeds.add(embed);
return embed;
}
public Embed embedVideo(File file) {
StepResult stepResult = result.addFakeStepResult("[video]", null);
Embed embed = saveToFileAndCreateEmbed(FileUtils.toBytes(file), ResourceType.MP4);
stepResult.addEmbed(embed);
return embed;
}
private List callResults;
public void addCallResult(FeatureResult fr) {
if (callResults == null) {
callResults = new ArrayList();
}
callResults.add(fr);
}
public LogAppender getLogAppender() {
return logAppender;
}
private List steps;
private List