Skip to content

Commit

Permalink
Merge pull request #3 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Aug 28, 2020
2 parents 5f49104 + af11de2 commit 279f9c1
Show file tree
Hide file tree
Showing 40 changed files with 1,548 additions and 147 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## [Unreleased]
### Fixed
- Incorrect item type settings
- Attribute reporting
- Test case id annotation on a step definition method reading
### Added
- Nested steps support

## [0.0.2-ALPHA]
### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Cucumber JVM version [6.0.0; ) adapter

[ ![Download](https://api.bintray.com/packages/epam/reportportal/agent-java-cucumber6/images/download.svg) ](https://bintray.com/epam/reportportal/agent-java-cucumber5/_latestVersion)


![CI Build](https://github.com/reportportal/agent-java-cucumber6/workflows/CI%20Build/badge.svg)
[![Join Slack chat!](https://reportportal-slack-auto.herokuapp.com/badge.svg)](https://reportportal-slack-auto.herokuapp.com)
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)
[![UserVoice](https://img.shields.io/badge/uservoice-vote%20ideas-orange.svg?style=flat)](https://rpp.uservoice.com/forums/247117-report-portal)
Expand Down
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ publishing {
}

dependencies {
api 'com.epam.reportportal:client-java:5.0.6'
api 'com.epam.reportportal:client-java:5.0.7'
api 'com.epam.reportportal:commons-model:5.0.0'
api 'com.google.code.findbugs:jsr305:3.0.2'

implementation 'io.cucumber:cucumber-java:6.0.0'

testImplementation('com.github.reportportal:agent-java-test-utils:ddcf50ee20')

testImplementation 'io.cucumber:cucumber-testng:6.0.0'
testImplementation 'org.aspectj:aspectjweaver:1.9.2'
testImplementation 'org.hamcrest:hamcrest-core:2.2'
testImplementation 'org.mockito:mockito-core:3.3.3'
testImplementation 'io.cucumber:cucumber-testng:6.0.0'
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
testImplementation 'com.epam.reportportal:logger-java-logback:5.0.3'
testImplementation ('org.junit.platform:junit-platform-runner:1.6.2') {
Expand All @@ -71,7 +72,13 @@ dependencies {
}

test {
outputs.upToDateWhen { return false }
useJUnitPlatform()
maxParallelForks(5) // it's forks - separate JVMs, should not interfere each other
doFirst {
def weaver = configurations.testRuntimeClasspath.find { it.name.contains("aspectjweaver") }
jvmArgs += "-javaagent:$weaver"
}
}

wrapper {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=0.0.3-ALPHA-SNAPSHOT
version=5.0.0-BETA-1-SNAPSHOT
description=EPAM Report portal. Cucumber version 6 integration
23 changes: 12 additions & 11 deletions src/main/java/com/epam/reportportal/cucumber/AbstractReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public abstract class AbstractReporter implements ConcurrentEventListener {
// End of feature occurs once launch is finished.
private final Map<URI, Date> featureEndTime = new ConcurrentHashMap<>();

private final Map<Long, RunningContext.ScenarioContext> threadCurrentScenarioContextMap = new ConcurrentHashMap<>();
private final ThreadLocal<RunningContext.ScenarioContext> currentScenarioContext = new ThreadLocal<>();

/**
* Registers an event handler for a specific event.
Expand Down Expand Up @@ -100,7 +100,7 @@ public void setEventPublisher(EventPublisher publisher) {
}

protected RunningContext.ScenarioContext getCurrentScenarioContext() {
return threadCurrentScenarioContextMap.get(Thread.currentThread().getId());
return currentScenarioContext.get();
}

/**
Expand Down Expand Up @@ -152,16 +152,17 @@ protected void beforeScenario(RunningContext.FeatureContext currentFeatureContex
* Put scenario end time in a map to check last scenario end time per feature
*/
protected void afterScenario(TestCaseFinished event) {
RunningContext.ScenarioContext currentScenarioContext = getCurrentScenarioContext();
RunningContext.ScenarioContext context = getCurrentScenarioContext();
for (Map.Entry<Pair<String, URI>, RunningContext.ScenarioContext> scenarioContext : currentScenarioContextMap.entrySet()) {
if (scenarioContext.getValue().getLine() == currentScenarioContext.getLine()) {
if (scenarioContext.getValue().getLine() == context.getLine()) {
currentScenarioContextMap.remove(scenarioContext.getKey());
Date endTime = Utils.finishTestItem(launch.get(), currentScenarioContext.getId(), event.getResult().getStatus());
Date endTime = Utils.finishTestItem(launch.get(), context.getId(), event.getResult().getStatus());
URI featureURI = scenarioContext.getKey().getValue();
featureEndTime.put(featureURI, endTime);
break;
}
}
currentScenarioContext.set(null);
}

/**
Expand Down Expand Up @@ -377,15 +378,15 @@ protected void handleStartOfTestCase(TestCaseStarted event) {
);

Pair<String, URI> scenarioNameFeatureURI = Pair.of(testCase.getScenarioDesignation(), currentFeatureContext.getUri());
RunningContext.ScenarioContext currentScenarioContext = currentScenarioContextMap.get(scenarioNameFeatureURI);
RunningContext.ScenarioContext context = currentScenarioContextMap.get(scenarioNameFeatureURI);

if (currentScenarioContext == null) {
currentScenarioContext = currentFeatureContext.getScenarioContext(testCase);
currentScenarioContextMap.put(scenarioNameFeatureURI, currentScenarioContext);
threadCurrentScenarioContextMap.put(Thread.currentThread().getId(), currentScenarioContext);
if (context == null) {
context = currentFeatureContext.getScenarioContext(testCase);
currentScenarioContextMap.put(scenarioNameFeatureURI, context);
currentScenarioContext.set(context);
}

beforeScenario(currentFeatureContext, currentScenarioContext, scenarioName);
beforeScenario(currentFeatureContext, context, scenarioName);
}

protected void handleTestStepStarted(TestStepStarted event) {
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/com/epam/reportportal/cucumber/RunningContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import io.cucumber.gherkin.TokenMatcher;
import io.cucumber.messages.IdGenerator;
import io.cucumber.messages.Messages;
import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.TestCase;
import io.cucumber.plugin.event.TestSourceRead;
import io.cucumber.plugin.event.TestStep;
import io.cucumber.plugin.event.*;
import io.reactivex.Maybe;

import java.net.URI;
Expand Down Expand Up @@ -140,7 +137,11 @@ <T extends Messages.GherkinDocument.Feature.Scenario> T getScenario(TestCase tes

static class ScenarioContext {
private static final Map<Messages.GherkinDocument.Feature.Scenario, List<Integer>> scenarioOutlineMap = new ConcurrentHashMap<>();
private Maybe<String> id = null;

private Maybe<String> currentStepId;
private Maybe<String> hookStepId;
private Status hookStatus;
private Maybe<String> id;
private Messages.GherkinDocument.Feature.Background background;
private Messages.GherkinDocument.Feature.Scenario scenario;
private final Queue<Messages.GherkinDocument.Feature.Step> backgroundSteps;
Expand Down Expand Up @@ -272,5 +273,29 @@ boolean hasBackground() {
String getOutlineIteration() {
return outlineIteration;
}

public Maybe<String> getCurrentStepId() {
return currentStepId;
}

public void setCurrentStepId(Maybe<String> currentStepId) {
this.currentStepId = currentStepId;
}

public Maybe<String> getHookStepId() {
return hookStepId;
}

public void setHookStepId(Maybe<String> hookStepId) {
this.hookStepId = hookStepId;
}

public Status getHookStatus() {
return hookStatus;
}

public void setHookStatus(Status hookStatus) {
this.hookStatus = hookStatus;
}
}
}
49 changes: 31 additions & 18 deletions src/main/java/com/epam/reportportal/cucumber/ScenarioReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/
package com.epam.reportportal.cucumber;

import com.epam.reportportal.service.Launch;
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import io.cucumber.messages.Messages;
import io.cucumber.plugin.event.*;
import io.reactivex.Maybe;
import org.apache.commons.lang3.tuple.Pair;
import rp.com.google.common.base.Supplier;
import rp.com.google.common.base.Suppliers;

Expand Down Expand Up @@ -47,14 +49,14 @@
*/
public class ScenarioReporter extends AbstractReporter {
private static final String SEPARATOR = " --- ";
private static final String RP_TEST_TYPE = "TEST";
private static final String RP_STORY_TYPE = "SUITE";
private static final String RP_TEST_TYPE = "STORY";
private static final String RP_STEP_TYPE = "STEP";
private static final String HOOK_COLON = "Hook:";
private static final String COLON_ = ": ";
private static final String STEP_ = "STEP ";
private static final String EMPTY_SUFFIX = "";
private static final String INFO = "INFO";
private static final String RP_STORY_TYPE = "STORY";
private static final String DUMMY_ROOT_SUITE_NAME = "Root User Story";

protected Supplier<Maybe<String>> rootSuiteId;
Expand All @@ -67,38 +69,49 @@ protected void beforeLaunch() {

@Override
protected void beforeStep(TestStep testStep) {
RunningContext.ScenarioContext currentScenarioContext = getCurrentScenarioContext();
Messages.GherkinDocument.Feature.Step step = currentScenarioContext.getStep(testStep);
int lineInFeatureFile = step.getLocation().getLine();
String decoratedStepName = lineInFeatureFile + decorateMessage(Utils.buildNodeName(currentScenarioContext.getStepPrefix(),
step.getKeyword(),
Utils.getStepName(testStep),
EMPTY_SUFFIX
));
String multilineArg = Utils.buildMultilineArgument(testStep);
Utils.sendLog(decoratedStepName + multilineArg, INFO);
RunningContext.ScenarioContext context = getCurrentScenarioContext();
Messages.GherkinDocument.Feature.Step step = context.getStep(testStep);
StartTestItemRQ rq = Utils.buildStartStepRequest(context.getStepPrefix(), testStep, step, false);
context.setCurrentStepId(launch.get().startTestItem(context.getId(), rq));
}

@Override
protected void afterStep(Result result) {
if (result.getStatus() != Status.PASSED) {
reportResult(result, decorateMessage(STEP_ + result.getStatus().name().toUpperCase()));
}
reportResult(result, null);
RunningContext.ScenarioContext context = getCurrentScenarioContext();
Launch myLaunch = launch.get();
Utils.finishTestItem(myLaunch, context.getCurrentStepId(), result.getStatus());
context.setCurrentStepId(null);
myLaunch.getStepReporter().finishPreviousStep();
}

@Override
protected void beforeHooks(HookType hookType) {
// noop
StartTestItemRQ rq = new StartTestItemRQ();
rq.setHasStats(false);
Pair<String, String> typeName = Utils.getHookTypeAndName(hookType);
rq.setType(typeName.getKey());
rq.setName(typeName.getValue());
rq.setStartTime(Calendar.getInstance().getTime());

RunningContext.ScenarioContext context = getCurrentScenarioContext();
context.setHookStepId(launch.get().startTestItem(getCurrentScenarioContext().getId(), rq));
context.setHookStatus(Status.PASSED);
}

@Override
protected void afterHooks(Boolean isBefore) {
// noop
RunningContext.ScenarioContext context = getCurrentScenarioContext();
Launch myLaunch = launch.get();
Utils.finishTestItem(myLaunch, context.getHookStepId(), context.getHookStatus());
context.setHookStepId(null);
myLaunch.getStepReporter().finishPreviousStep();
}

@Override
protected void hookFinished(HookTestStep step, Result result, Boolean isBefore) {
reportResult(result, step.getHookType().name() + HOOK_COLON + result.getStatus() + COLON_ + step.getCodeLocation());
reportResult(result, (isBefore ? "Before" : "After") + " hook: " + step.getCodeLocation());
getCurrentScenarioContext().setHookStatus(result.getStatus());
}

@Override
Expand Down
Loading

0 comments on commit 279f9c1

Please sign in to comment.