Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8244b53
add initial draft for cucumber-jvm plugin base it on testng plugin
clicman Mar 1, 2017
788772e
generate features and scenarios
clicman Mar 2, 2017
762f8b2
add debug test
clicman Mar 4, 2017
b8670c9
add debug test
clicman Mar 4, 2017
fb6bd40
move junit to test scope
clicman Mar 6, 2017
73094b7
first working variant
clicman Mar 19, 2017
51e6829
add links support
clicman Mar 19, 2017
4ceb71b
managing tags
clicman Mar 19, 2017
f60627f
Fix cucumber-jvm bug
clicman Mar 19, 2017
a198521
Finish main behaviour.
clicman Mar 19, 2017
32e3601
Handle befores and afters
clicman Mar 19, 2017
62eab17
Sort methods by its purpose
clicman Mar 20, 2017
100ddcd
fix unimplemented on failure
clicman Mar 20, 2017
e34db7d
add more clear message on before failing
clicman Mar 20, 2017
58d08ec
Fix problems with fully unimplemented steps
clicman Mar 20, 2017
4fa6303
add attachment tag
clicman Mar 20, 2017
2f4a3ca
comments on .gitignore
clicman Mar 20, 2017
0ef3da8
Add description to scenarios
clicman Mar 20, 2017
da2fd33
Merge branch 'master' into allure-cucumber-jvm
clicman Mar 20, 2017
9c35868
Fix trivial Checkstyle errors
clicman Mar 20, 2017
ee1a966
Fix lint errors
clicman Mar 20, 2017
fdf4f13
Merge branch 'master' into allure-cucumber-jvm
clicman Mar 21, 2017
f2aa319
Add compile-time encoding value
clicman Mar 21, 2017
382db4e
Refactoring for ResultUtils.getStatusDeatils use
clicman Mar 21, 2017
75cf91a
Merge remote-tracking branch 'origin/allure-cucumber-jvm' into allure…
clicman Mar 21, 2017
8a65616
Fix imports... Again.
clicman Mar 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle
schema
build
/*/allure-results/

#IDEA Files
.idea
Expand All @@ -15,3 +16,6 @@ build

#Mac OS stuff
.DS_Store

#Netbeans files
/.nb-gradle/
38 changes: 38 additions & 0 deletions allure-cucumber-jvm/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
description = 'Allure CucumberJVM'

configurations {
agent
}

dependencies {
agent 'org.aspectj:aspectjweaver'

compile project(':allure-java-commons')
compile 'info.cukes:gherkin:2.12.2'
compile 'info.cukes:cucumber-core:1.2.5'
compile 'info.cukes:cucumber-java:1.2.5'
compile 'info.cukes:cucumber-junit:1.2.5'

testCompile 'junit:junit:4.12'


}

test.doFirst {
jvmArgs "-javaagent:${configurations.agent.singleFile}"
}

test {
systemProperty 'allure.model.indentOutput', true
systemProperty 'allure.results.directory', 'build/allure-results'
}


task spiOffJar(type: Jar, dependsOn: classes) {
classifier = 'spi-off'
from sourceSets.main.allJava
}

artifacts {
archives spiOffJar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
package io.qameta.allure.cucumberjvm;

import cucumber.runtime.StepDefinitionMatch;
import gherkin.I18n;
import gherkin.formatter.Formatter;
import gherkin.formatter.Reporter;
import gherkin.formatter.model.Background;
import gherkin.formatter.model.Examples;
import gherkin.formatter.model.Feature;
import gherkin.formatter.model.Match;
import gherkin.formatter.model.Result;
import gherkin.formatter.model.Scenario;
import gherkin.formatter.model.ScenarioOutline;
import gherkin.formatter.model.Step;
import gherkin.formatter.model.Tag;
import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.ResultsUtils;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.model.TestResult;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;


/**
* Allure plugin for Cucumber-JVM.
*/
public class AllureCucumberJvm implements Reporter, Formatter {

private static final List<String> SCENARIO_OUTLINE_KEYWORDS = Collections.synchronizedList(new ArrayList<String>());

private static final String FAILED = "failed";
private static final String PASSED = "passed";
private static final String SKIPPED = "skipped";


private final Deque<Step> gherkinSteps = new LinkedList<>();
private final AllureLifecycle lifecycle;
private Feature currentFeature;
private boolean isNullMatch = true;
private Scenario currentScenario;


public AllureCucumberJvm() {
this.lifecycle = Allure.getLifecycle();
final List<I18n> i18nList = I18n.getAll();

i18nList.forEach(i18n -> SCENARIO_OUTLINE_KEYWORDS.addAll(i18n.keywords("scenario_outline")));
}

@Override
public void feature(final Feature feature) {
this.currentFeature = feature;
}

@Override
public void before(final Match match, final Result result) {
new StepUtils(currentFeature, currentScenario).fireFixtureStep(match, result, true);
}

@Override
public void after(final Match match, final Result result) {
new StepUtils(currentFeature, currentScenario).fireFixtureStep(match, result, false);
}

@Override
public void startOfScenarioLifeCycle(final Scenario scenario) {
this.currentScenario = scenario;

final Deque<Tag> tags = new LinkedList<>();
tags.addAll(scenario.getTags());

if (SCENARIO_OUTLINE_KEYWORDS.contains(scenario.getKeyword())) {
synchronized (gherkinSteps) {
gherkinSteps.clear();
}
} else {
tags.addAll(currentFeature.getTags());
}

final LabelBuilder labelBuilder = new LabelBuilder(currentFeature, scenario, tags);


final TestResult result = new TestResult()
.withUuid(scenario.getId())
.withHistoryId(StepUtils.getHistoryId(scenario.getId()))
.withName(scenario.getName())
.withLabels(labelBuilder.getScenarioLabels())
.withLinks(labelBuilder.getScenarioLinks());

if (!currentFeature.getDescription().isEmpty()) {
result.withDescription(currentFeature.getDescription());
}

lifecycle.scheduleTestCase(result);
lifecycle.startTestCase(scenario.getId());

}

@Override
public void step(final Step step) {
synchronized (gherkinSteps) {
gherkinSteps.add(step);
}
}

@Override
public void match(final Match match) {
final StepUtils stepUtils = new StepUtils(currentFeature, currentScenario);
if (match instanceof StepDefinitionMatch) {
isNullMatch = false;
final Step step = stepUtils.extractStep((StepDefinitionMatch) match);
synchronized (gherkinSteps) {
while (gherkinSteps.peek() != null && !stepUtils.isEqualSteps(step, gherkinSteps.peek())) {
stepUtils.fireCanceledStep(gherkinSteps.remove());
}
if (stepUtils.isEqualSteps(step, gherkinSteps.peek())) {
gherkinSteps.remove();
}
}
final StepResult stepResult = new StepResult();
stepResult.withName(String.format("%s %s", step.getKeyword(), step.getName()))
.withStart(System.currentTimeMillis());
lifecycle.startStep(currentScenario.getId(), stepUtils.getStepUuid(step), stepResult);
}
}

@Override
public void result(final Result result) {
if (!isNullMatch) {
final StatusDetails statusDetails = new StatusDetails();
final TagParser tagParser = new TagParser(currentFeature, currentScenario);
statusDetails
.withFlaky(tagParser.isFlaky())
.withMuted(tagParser.isMuted())
.withKnown(tagParser.isKnown());

switch (result.getStatus()) {
case FAILED:
lifecycle.updateStep(stepResult -> stepResult.withStatus(Status.FAILED));
lifecycle.updateTestCase(currentScenario.getId(), scenarioResult ->
scenarioResult.withStatus(Status.FAILED)
.withStatusDetails(ResultsUtils.getStatusDetails(result.getError()).get()));
lifecycle.stopStep();
break;
case SKIPPED:
lifecycle.updateStep(stepResult -> stepResult.withStatus(Status.SKIPPED));
lifecycle.stopStep();
break;
case PASSED:
lifecycle.updateStep(stepResult -> stepResult.withStatus(Status.PASSED));
lifecycle.stopStep();
lifecycle.updateTestCase(currentScenario.getId(), scenarioResult ->
scenarioResult.withStatus(Status.PASSED)
.withStatusDetails(statusDetails));
break;
default:
break;
}
isNullMatch = true;
}
}

@Override
public void endOfScenarioLifeCycle(final Scenario scenario) {
final StepUtils stepUtils = new StepUtils(currentFeature, currentScenario);
synchronized (gherkinSteps) {
while (gherkinSteps.peek() != null) {
stepUtils.fireCanceledStep(gherkinSteps.remove());
}
}
lifecycle.stopTestCase(scenario.getId());
lifecycle.writeTestCase(scenario.getId());
}

@Override
public void embedding(final String string, final byte[] bytes) {
//Nothing to do with Allure
}

@Override
public void write(final String string) {
//Nothing to do with Allure
}

@Override
public void syntaxError(final String state, final String event,
final List<String> legalEvents, final String uri, final Integer line) {
//Nothing to do with Allure
}

@Override
public void uri(final String uri) {
//Nothing to do with Allure
}

@Override
public void scenarioOutline(final ScenarioOutline so) {
//Nothing to do with Allure
}

@Override
public void examples(final Examples exmpls) {
//Nothing to do with Allure
}


@Override
public void background(final Background b) {
//Nothing to do with Allure
}

@Override
public void scenario(final Scenario scnr) {
//Nothing to do with Allure
}

@Override
public void done() {
//Nothing to do with Allure
}

@Override
public void close() {
//Nothing to do with Allure
}

@Override
public void eof() {
//Nothing to do with Allure

}

}
Loading