Skip to content

Commit

Permalink
Merge pull request #43 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Dec 5, 2023
2 parents 3df3b15 + 6d09496 commit ee134ac
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 38 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.1.24](https://github.com/reportportal/client-java/releases/tag/5.1.24), by @HardNorth
- `ReportPortalSpockListener.logError` now sends exceptions directly to RP bypassing logging to reduce amount of user misconfigurations, by @HardNorth

## [5.1.3]
### Changed
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
> after a successful launch start. This information might help us to improve both ReportPortal backend and client sides. It is used by the
> ReportPortal team only and is not supposed for sharing with 3rd parties.
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-spock.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-spock%22)
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-spock.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-spock)
[![CI Build](https://github.com/reportportal/agent-java-spock/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-spock/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/agent-java-spock/branch/develop/graph/badge.svg?token=Vnk338Rigx)](https://codecov.io/gh/reportportal/agent-java-spock)
[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/)
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)

The latest version: 5.1.3. Please use `Maven Central` link above to get the client.

## Video Tutorial for integration of SPOCK on Groovy
[![Spock on Groovy](https://img.youtube.com/vi/Rkm8dpTZur8/0.jpg)](https://www.youtube.com/watch?v=Rkm8dpTZur8)

Expand Down Expand Up @@ -93,7 +95,7 @@ testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
```
*Spock framework dependency*
```gradle
testCompile ("org.spockframework:spock-core:1.3-groovy-2.5") {
testCompile ("org.spockframework:spock-core:2.3-groovy-2.5") {
exclude group: "org.codehaus.groovy"
}
```
Expand All @@ -105,28 +107,28 @@ If you prefer using *Logback* logging library, add following dependencies:

*ReportPortal logback logger dependency*
```gradle
testCompile 'com.epam.reportportal:logger-java-logback:5.1.1'
testCompile 'com.epam.reportportal:logger-java-logback:5.1.6'
```

> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-logback%22)
*The logback itself*
```gradle
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.10'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.8'
```

If you prefer using *Log4j* logging library, add following dependencies:

*ReportPortal log4j logger dependency*
```gradle
testCompile 'com.epam.reportportal:logger-java-log4j:5.1.4'
testCompile 'com.epam.reportportal:logger-java-log4j:5.1.8'
```
> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-log4j%22)
*The log4j itself*
```gradle
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.2'
```

#### 2.4 Create gradle tasks for tests
Expand Down Expand Up @@ -180,22 +182,22 @@ repositories {
dependencies {
testCompile 'com.epam.reportportal:agent-java-spock:5.1.3'
testCompile 'com.epam.reportportal:logger-java-logback:5.1.1'
testCompile 'com.epam.reportportal:logger-java-logback:5.1.6'
testCompile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
testCompile "org.gebish:geb-spock:$gebVersion"
testCompile "org.gebish:geb-junit4:$gebVersion"
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
testCompile ("org.spockframework:spock-core:1.3-groovy-2.5") {
testCompile ("org.spockframework:spock-core:2.3-groovy-2.5") {
exclude group: "org.codehaus.groovy"
}
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
testCompile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
testCompile "org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion"
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.10'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.8'
}
drivers.each { driver ->
Expand Down Expand Up @@ -432,7 +434,7 @@ Returning back to the code. In your project, create file named `reportportal.pro
[resources/reportportal.properties]

rp.endpoint = http://localhost:8080
rp.uuid = your_reportportal_api_key
rp.api.key = your_reportportal_api_key
rp.launch = robin_tests
rp.project = my_cool_project
rp.enable = true
Expand Down Expand Up @@ -628,6 +630,6 @@ reportingListener = new RpScreenshotListener()

Now we should be able to see the screenshot of the page after opening Google's start page and also in case of the test failure

![Attahced screenshot to the ReportPortal logs](integration_manual_files/step_attached_screenshot_1.png)
![Attached screenshot to the ReportPortal logs](integration_manual_files/step_attached_screenshot_1.png)

![Opened screenshot from the ReportPortal logs](integration_manual_files/step_attached_screenshot_2.png)
26 changes: 14 additions & 12 deletions README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
> after a successful launch start. This information might help us to improve both ReportPortal backend and client sides. It is used by the
> ReportPortal team only and is not supposed for sharing with 3rd parties.
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-spock.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-spock%22)
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-spock.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-spock)
[![CI Build](https://github.com/reportportal/agent-java-spock/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-spock/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/agent-java-spock/branch/develop/graph/badge.svg?token=Vnk338Rigx)](https://codecov.io/gh/reportportal/agent-java-spock)
[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/)
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)

The latest version: $LATEST_VERSION. Please use `Maven Central` link above to get the client.

## Video Tutorial for integration of SPOCK on Groovy
[![Spock on Groovy](https://img.youtube.com/vi/Rkm8dpTZur8/0.jpg)](https://www.youtube.com/watch?v=Rkm8dpTZur8)

Expand Down Expand Up @@ -93,7 +95,7 @@ testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
```
*Spock framework dependency*
```gradle
testCompile ("org.spockframework:spock-core:1.3-groovy-2.5") {
testCompile ("org.spockframework:spock-core:2.3-groovy-2.5") {
exclude group: "org.codehaus.groovy"
}
```
Expand All @@ -105,28 +107,28 @@ If you prefer using *Logback* logging library, add following dependencies:

*ReportPortal logback logger dependency*
```gradle
testCompile 'com.epam.reportportal:logger-java-logback:5.1.1'
testCompile 'com.epam.reportportal:logger-java-logback:5.1.6'
```

> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-logback%22)
*The logback itself*
```gradle
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.10'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.8'
```

If you prefer using *Log4j* logging library, add following dependencies:

*ReportPortal log4j logger dependency*
```gradle
testCompile 'com.epam.reportportal:logger-java-log4j:5.1.4'
testCompile 'com.epam.reportportal:logger-java-log4j:5.1.8'
```
> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-log4j%22)
*The log4j itself*
```gradle
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.2'
```

#### 2.4 Create gradle tasks for tests
Expand Down Expand Up @@ -180,22 +182,22 @@ repositories {
dependencies {
testCompile 'com.epam.reportportal:agent-java-spock:$LATEST_VERSION'
testCompile 'com.epam.reportportal:logger-java-logback:5.1.1'
testCompile 'com.epam.reportportal:logger-java-logback:5.1.6'
testCompile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
testCompile "org.gebish:geb-spock:$gebVersion"
testCompile "org.gebish:geb-junit4:$gebVersion"
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
testCompile ("org.spockframework:spock-core:1.3-groovy-2.5") {
testCompile ("org.spockframework:spock-core:2.3-groovy-2.5") {
exclude group: "org.codehaus.groovy"
}
testCompile "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
testCompile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
testCompile "org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion"
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.10'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.8'
}
drivers.each { driver ->
Expand Down Expand Up @@ -432,7 +434,7 @@ Returning back to the code. In your project, create file named `reportportal.pro
[resources/reportportal.properties]

rp.endpoint = http://localhost:8080
rp.uuid = your_reportportal_api_key
rp.api.key = your_reportportal_api_key
rp.launch = robin_tests
rp.project = my_cool_project
rp.enable = true
Expand Down Expand Up @@ -628,6 +630,6 @@ reportingListener = new RpScreenshotListener()

Now we should be able to see the screenshot of the page after opening Google's start page and also in case of the test failure

![Attahced screenshot to the ReportPortal logs](integration_manual_files/step_attached_screenshot_1.png)
![Attached screenshot to the ReportPortal logs](integration_manual_files/step_attached_screenshot_1.png)

![Opened screenshot from the ReportPortal logs](integration_manual_files/step_attached_screenshot_2.png)
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {
}

dependencies {
api "com.epam.reportportal:client-java:5.1.22"
api "com.epam.reportportal:client-java:5.1.24"
api "com.epam.reportportal:commons-model:5.0.0"
api "org.spockframework:spock-core:${spock_version}"
api 'com.google.code.findbugs:jsr305:3.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author Dzmitry Mikhievich
*/
abstract class AbstractLaunchContext {
public abstract class AbstractLaunchContext {

private Maybe<String> launchId;
private final AtomicReference<Boolean> launchInProgress = new AtomicReference<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author Dzmitry Mikhievich
*/
abstract class NodeFootprint<T extends NodeInfo> extends ReportableItemFootprint<T> {
public abstract class NodeFootprint<T extends NodeInfo> extends ReportableItemFootprint<T> {

/*
* Approximate fixtures count, which should match most cases. This is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public void reportFixtureError(@Nonnull SpecInfo spec, @Nullable FeatureInfo fea

protected void logError(@Nonnull ErrorInfo error) {
Throwable exception = error.getException();
LoggerFactory.getLogger(error.getMethod().getReflection().getDeclaringClass()).error(exception.getLocalizedMessage(), exception);
ReportPortal.sendStackTraceToRP(exception);
}

public void reportError(@Nonnull ErrorInfo error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @author Dzmitry Mikhievich
*/
abstract class ReportableItemFootprint<T extends NodeInfo> {
public abstract class ReportableItemFootprint<T extends NodeInfo> {

static final Predicate<ReportableItemFootprint> IS_NOT_PUBLISHED = input -> input != null && !input.isPublished();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.service.ReportPortalClient;
import com.epam.reportportal.spock.ReportPortalSpockListener;
import com.epam.reportportal.spock.features.FailsWithAnnotationFail;
import com.epam.reportportal.spock.features.fail.FailsWithAnnotationFail;
import com.epam.reportportal.spock.utils.TestExtension;
import com.epam.reportportal.spock.utils.TestUtils;
import com.epam.reportportal.util.test.CommonUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright 2021 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.spock.fail;

import com.epam.reportportal.listeners.ItemStatus;
import com.epam.reportportal.listeners.ItemType;
import com.epam.reportportal.listeners.LogLevel;
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.service.ReportPortalClient;
import com.epam.reportportal.spock.ReportPortalSpockListener;
import com.epam.reportportal.spock.features.fail.FailsInDifferentMethod;
import com.epam.reportportal.spock.utils.TestExtension;
import com.epam.reportportal.spock.utils.TestUtils;
import com.epam.reportportal.util.test.CommonUtils;
import com.epam.ta.reportportal.ws.model.FinishExecutionRQ;
import com.epam.ta.reportportal.ws.model.FinishTestItemRQ;
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import com.epam.ta.reportportal.ws.model.log.SaveLogRQ;
import okhttp3.MultipartBody;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import org.mockito.ArgumentCaptor;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.epam.reportportal.spock.utils.TestUtils.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

public class TestFailsWithStackTrace {

private final String launchId = CommonUtils.namedId("launch_");
private final String classId = CommonUtils.namedId("class_");
private final List<String> methodIds = Stream.generate(() -> CommonUtils.namedId("method_")).limit(1).collect(Collectors.toList());

private final ReportPortalClient client = mock(ReportPortalClient.class);

@BeforeEach
public void setupMock() {
TestUtils.mockLaunch(client, launchId, classId, methodIds);
TestUtils.mockBatchLogging(client);
TestExtension.listener = new ReportPortalSpockListener(ReportPortal.create(client, standardParameters(), testExecutor()));
}

@Test
@SuppressWarnings("unchecked")
public void verify_fail_with_failed_reporting() {
TestExecutionSummary result = runClasses(FailsInDifferentMethod.class);

assertThat(result.getTotalFailureCount(), equalTo(1L));

verify(client).startLaunch(any());
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client).startTestItem(any(StartTestItemRQ.class));
verify(client, times(1)).startTestItem(same(classId), startCaptor.capture());

List<StartTestItemRQ> items = startCaptor.getAllValues();

items.forEach(i -> {
assertThat(i.getType(), equalTo(ItemType.STEP.name()));
assertThat(i.isHasStats(), equalTo(Boolean.TRUE));
});

ArgumentCaptor<FinishTestItemRQ> finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
methodIds.forEach(s -> verify(client).finishTestItem(eq(s), finishStepCaptor.capture()));

List<String> finishItemStatuses = finishStepCaptor.getAllValues()
.stream()
.map(FinishExecutionRQ::getStatus)
.collect(Collectors.toList());

assertThat(finishItemStatuses, hasSize(1));
assertThat(finishItemStatuses.get(0), equalTo(ItemStatus.FAILED.name()));
verify(client).finishTestItem(eq(classId), any());
verify(client).finishLaunch(eq(launchId), any());

ArgumentCaptor<List<MultipartBody.Part>> logCaptor = ArgumentCaptor.forClass(List.class);
verify(client, atLeast(1)).log(logCaptor.capture());
List<SaveLogRQ> rqs = toSaveLogRQ(logCaptor.getAllValues()).stream()
.filter(rq -> LogLevel.ERROR.name().equals(rq.getLevel()))
.collect(Collectors.toList());
assertThat(rqs, hasSize(1));
assertThat(rqs.get(0).getMessage(), containsString("FailsInDifferentMethod.anotherFailedMethod"));

//noinspection unchecked
verify(client, atLeast(1)).log(any(List.class));
verifyNoMoreInteractions(client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.service.ReportPortalClient;
import com.epam.reportportal.spock.ReportPortalSpockListener;
import com.epam.reportportal.spock.features.HelloSpockSpecUnrollFailed;
import com.epam.reportportal.spock.features.fail.HelloSpockSpecUnrollFailed;
import com.epam.reportportal.spock.utils.TestExtension;
import com.epam.reportportal.spock.utils.TestUtils;
import com.epam.reportportal.util.test.CommonUtils;
Expand Down
Loading

0 comments on commit ee134ac

Please sign in to comment.