Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 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 30a680e + a225a66 commit b9a3aa8
Show file tree
Hide file tree
Showing 38 changed files with 1,605 additions and 216 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## [Unreleased]
### Fixed
- A bug when ambiguous item cases a Null Pointer Exception
- Incorrect item type settings
### Added
- Nested steps support

## [5.0.0-BETA-13]
### Added
Expand Down
83 changes: 42 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# Cucumber3 Agent for ReportPortal
[ ![Download](https://api.bintray.com/packages/epam/reportportal/agent-java-cucumber3/images/download.svg) ](https://bintray.com/epam/reportportal/agent-java-cucumber3/_latestVersion)

[![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)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)


### Installation

Add to POM.xml

**dependency**

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-epam-reportportal</id>
<name>bintray</name>
<url>http://dl.bintray.com/epam/reportportal</url>
</repository>
</repositories>
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>agent-java-cucumber3</artifactId>
<version>0.0.1-beta</version>
<type>pom</type>
</dependency>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### Install Reporter, Configuration

See readme for Cucumber Agent 2 for details on installation and configuration (as this (3rd) version of agent is a copy of the 2nd version with minor chagnes in dependencies) - https://github.com/reportportal/agent-java-cucumber2


# Cucumber3 Agent for ReportPortal
[ ![Download](https://api.bintray.com/packages/epam/reportportal/agent-java-cucumber3/images/download.svg) ](https://bintray.com/epam/reportportal/agent-java-cucumber3/_latestVersion)

![CI Build](https://github.com/reportportal/agent-java-cucumber3/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)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)


### Installation

Add to POM.xml

**dependency**

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-epam-reportportal</id>
<name>bintray</name>
<url>http://dl.bintray.com/epam/reportportal</url>
</repository>
</repositories>
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>agent-java-cucumber3</artifactId>
<version>0.0.1-beta</version>
<type>pom</type>
</dependency>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### Install Reporter, Configuration

See readme for Cucumber Agent 2 for details on installation and configuration (as this (3rd) version of agent is a copy of the 2nd version with minor chagnes in dependencies) - https://github.com/reportportal/agent-java-cucumber2


10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ 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:3.0.2'

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

testImplementation 'org.aspectj:aspectjweaver:1.9.2'
testImplementation 'org.hamcrest:hamcrest-core:2.2'
testImplementation 'org.mockito:mockito-core:3.3.3'
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
Expand All @@ -72,9 +73,16 @@ 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 {
gradleVersion = '5.4.1'
}
Expand Down
39 changes: 20 additions & 19 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 Formatter {

private final Map<Pair<String, String>, RunningContext.ScenarioContext> currentScenarioContextMap = new ConcurrentHashMap<>();

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

// There is no event for recognizing end of feature in Cucumber.
// This map is used to record the last scenario time and its feature uri.
Expand Down Expand Up @@ -134,35 +134,36 @@ protected void afterLaunch() {
* Start Cucumber scenario
*/
protected void beforeScenario(RunningContext.FeatureContext currentFeatureContext,
RunningContext.ScenarioContext currentScenarioContext, String scenarioName) {
RunningContext.ScenarioContext context, String scenarioName) {
String description = getDescription(currentFeatureContext.getUri());
String codeRef = getCodeRef(currentFeatureContext.getUri(), currentScenarioContext.getLine());
String codeRef = getCodeRef(currentFeatureContext.getUri(), context.getLine());
Maybe<String> id = Utils.startNonLeafNode(launch.get(),
currentFeatureContext.getFeatureId(),
scenarioName,
description,
codeRef,
currentScenarioContext.getAttributes(),
context.getAttributes(),
getScenarioTestItemType()
);
currentScenarioContext.setId(id);
context.setId(id);
}

/**
* Finish Cucumber scenario
* 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, String>, 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.result.getStatus());
Date endTime = Utils.finishTestItem(launch.get(), context.getId(), event.result.getStatus());
String featureURI = scenarioContext.getKey().getValue();
featureEndTime.put(featureURI, endTime);
break;
}
}
currentScenarioContext.set(null);
}

/**
Expand Down Expand Up @@ -297,7 +298,7 @@ protected boolean isBefore(TestStep step) {
protected abstract Maybe<String> getRootItemId();

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

private RunningContext.FeatureContext createFeatureContext(TestCase testCase) {
Expand Down Expand Up @@ -381,23 +382,23 @@ private void handleStartOfTestCase(TestCaseStarted event) {
throw new IllegalStateException("Scenario URI does not match Feature URI.");
}

RunningContext.ScenarioContext scenarioContext = currentFeatureContext.getScenarioContext(testCase);
String scenarioName = Utils.buildNodeName(scenarioContext.getKeyword(),
RunningContext.ScenarioContext context = currentFeatureContext.getScenarioContext(testCase);
String scenarioName = Utils.buildNodeName(context.getKeyword(),
AbstractReporter.COLON_INFIX,
scenarioContext.getName(),
scenarioContext.getOutlineIteration()
context.getName(),
context.getOutlineIteration()
);

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

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

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

private void handleTestStepStarted(TestStepStarted event) {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/epam/reportportal/cucumber/RunningContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
import cucumber.api.PickleStepTestStep;
import cucumber.api.Result;
import cucumber.api.TestCase;
import cucumber.api.TestStep;
import cucumber.api.event.TestSourceRead;
Expand Down Expand Up @@ -154,6 +155,9 @@ static class ScenarioContext {
private final Map<Integer, Step> scenarioLocationMap = new HashMap<>();
private Set<ItemAttributesRQ> attributes = new HashSet<>();

private Maybe<String> currentStepId;
private Maybe<String> hookStepId;
private Result.Type hookStatus;
private Maybe<String> id = null;
private Background background;
private ScenarioDefinition scenario;
Expand Down Expand Up @@ -284,5 +288,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 Result.Type getHookStatus() {
return hookStatus;
}

public void setHookStatus(Result.Type hookStatus) {
this.hookStatus = hookStatus;
}
}
}
Loading

0 comments on commit b9a3aa8

Please sign in to comment.