io.github.testra.java.reporters.jbehave.Testra Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testra-java-jbehave-reporter Show documentation
Show all versions of testra-java-jbehave-reporter Show documentation
testra-java-jbehave-reporter for Testra
The newest version!
package io.github.testra.java.reporters.jbehave;
import io.github.testra.java.client.model.DataTableCell;
import io.github.testra.java.client.model.DataTableRow;
import io.github.testra.java.client.model.ScenarioRequest;
import io.github.testra.java.client.model.StepResult;
import io.github.testra.java.client.model.StepResult.StatusEnum;
import io.github.testra.java.client.model.TestStep;
import io.github.testra.java.commons.cons.ResultStatus;
import io.github.testra.java.commons.pojos.TestData;
import io.github.testra.java.reporter.TestraScenarioReporter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jbehave.core.annotations.AfterScenario.Outcome;
import org.jbehave.core.annotations.Scope;
import org.jbehave.core.configuration.Keywords;
import org.jbehave.core.model.ExamplesTable;
import org.jbehave.core.model.Lifecycle;
import org.jbehave.core.model.Scenario;
import org.jbehave.core.model.Story;
import org.jbehave.core.reporters.NullStoryReporter;
public class Testra extends NullStoryReporter {
private static final TestraScenarioReporter testraReporter = new TestraJBehaveReporter();
private static final ThreadLocal currentStory = new InheritableThreadLocal<>();
private static final ThreadLocal currentScenario = new InheritableThreadLocal<>();
private static final ThreadLocal stepStartTime = new ThreadLocal<>();
private static final ThreadLocal> stepResults = new ThreadLocal<>();
private static void setUpNewScenario(Scenario scenario, Map currentTableRow) {
long startTime = System.currentTimeMillis();
createTest(scenario, currentTableRow);
TestData testData =
TestData.builder()
.startTimeInMs(startTime)
.isExpectedToFail(scenario.getMeta()
.getPropertyNames()
.contains("ExpectedFailure"))
.build();
testraReporter.setTestData(testData);
stepResults.set(new ArrayList<>());
}
private static void createTest(Scenario scenario, Map currentTableRow) {
Story story = currentStory.get();
List backgroundSteps = getBackgroundSteps(story);
List steps = getSteps(backgroundSteps.size(), scenario);
List afterSteps = getAfterSteps(backgroundSteps.size() + steps.size(), story);
ScenarioRequest scenarioRequest =
new ScenarioRequest()
.featureName(story.getName())
.namespace(story.getPath())
.featureDescription(story.getNarrative()
.asString(new Keywords()))
.name(scenario.getTitle())
.backgroundSteps(backgroundSteps)
.steps(Stream.concat(steps.stream(), afterSteps.stream())
.collect(Collectors.toList()))
.tags(getTags(story, scenario))
.manual(scenario.getMeta()
.getPropertyNames()
.contains("Manual"));
if (currentTableRow != null) {
scenarioRequest.setDataRows(mapToDataRows(scenario.getExamplesTable(), currentTableRow));
}
testraReporter.setCurrentTest(testraReporter.createTest(scenarioRequest));
}
private static List mapToDataRows(
ExamplesTable examplesTable, Map currentTableRow) {
List headers = examplesTable.getHeaders();
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy